Please, unfortunately I have two problems

Created at 30 Jun 2018, 20:25
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
EO

eOs IT

Joined 21.09.2016

Please, unfortunately I have two problems
30 Jun 2018, 20:25


Hello everyone. This is my first speech on this forum. I hope I have written in the correct section and get a valid help.

Unfortunately I have two problems. One with a bot and one with an indicator.
I've been searching for solutions on the forum and on the Internet for weeks. Without success.
All the two codes are in Mql and have been successfully translated on 2calgo.com. 

The bot takes 1 to 3 seconds before it starts working (maybe because of about 3000 lines of code after translation) and I'm a scalper. Impossible to use.
An example: I have open operations. Three buy and two sell. 4 operations are winners and one a loser. Manually and in the shortest possible time (from a bot placed in a small detached window), I have to close all five operations at the same time (one after the other I know).

[IMG]http://icmarkets.ctrader.com/c/CGY6n[/IMG]

This is the original code:

int start()
{
   for (int i = (OrdersTotal() - 1); i >= 0; i--)
   {
      if      (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
      else if (OrderType() == OP_BUY)  OrderClose(OrderTicket(), OrderLots(), Bid, 0, Blue);
      else if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, 0, Blue);
   }
      return(0);
}


Instead, the indicator works correctly, but REVERSES the signal and is unusable.

[IMG]http://icmarkets.ctrader.com/c/1GY6n[/IMG]

 

This is the original code:

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 DarkBlue
#property indicator_color2 Maroon
extern int BarWidth = 4;
extern int       MACD_Fast=12;
extern int       MACD_Slow=20;
extern int       MACD_Signal=5;
extern int       Back_Bars=100;
extern bool      Set_Levels=true;
double Power_Buffer_Pos[];
double Power_Buffer_Neg[];
int init()
 {
   SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,BarWidth);
   SetIndexBuffer(0,Power_Buffer_Pos);
   SetIndexDrawBegin(0, Back_Bars);
   SetIndexLabel(0, NULL);
   SetIndexLabel(1, NULL);
   SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,BarWidth);
   SetIndexBuffer(1,Power_Buffer_Neg);
   SetIndexDrawBegin(1, Back_Bars);
   IndicatorShortName("");
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
   {
   int Bar_Index=0;
   int Pos_Bar_Count=0;
   int Neg_Bar_Count=0;
   double Total_Pos_Power=0;
   double Average_Pos_Power=0;
   double Total_Neg_Power=0;
   double Average_Neg_Power=0;
   int counted_bars=IndicatorCounted();
   for (Bar_Index = Back_Bars; Bar_Index >=0; Bar_Index--)
      {
      double MACD_Main = iMACD(Symbol(),0,MACD_Fast,MACD_Slow,MACD_Signal,PRICE_CLOSE,MODE_MAIN,Bar_Index);
      double MACD_Signal1 = iMACD(Symbol(),0,MACD_Fast,MACD_Slow,MACD_Signal,PRICE_CLOSE,MODE_SIGNAL,Bar_Index);
      double MACD_Diff = MACD_Main - MACD_Signal1;
     if (MACD_Diff > 0)
         {
         Power_Buffer_Pos[Bar_Index] = MACD_Diff;
         Power_Buffer_Neg[Bar_Index] = 0;
         Pos_Bar_Count = Pos_Bar_Count + 1;
         Total_Pos_Power = Total_Pos_Power +  MACD_Diff;
         }
      else if (MACD_Diff < 0)
         {
         Power_Buffer_Pos[Bar_Index] = 0;
         Power_Buffer_Neg[Bar_Index] = MACD_Diff;
         Neg_Bar_Count = Neg_Bar_Count + 1;
         Total_Neg_Power = Total_Neg_Power + MACD_Diff;
         }
      else if (MACD_Diff == 0)
         {
         Power_Buffer_Pos[Bar_Index] = 0;
         Power_Buffer_Neg[Bar_Index] = 0;
         }}
   Average_Pos_Power = Total_Pos_Power/Pos_Bar_Count;
   Average_Neg_Power = Total_Neg_Power/Neg_Bar_Count;
   if (Set_Levels == true)
      {
      SetLevelStyle( EMPTY, 1, C'20,20,20');
      SetLevelValue(1, Average_Pos_Power);
      SetLevelValue(2, Average_Neg_Power);
      }
   else if (Set_Levels == false)
      {
      SetLevelStyle( EMPTY, 1, C'20,20,20');
      SetLevelValue(1, 0);
      SetLevelValue(2, 0);
      }
   return(0);
   }


Can anyone help me kindly? Thank you.


@eOs IT
Replies

eOs IT
30 Jun 2018, 20:30 ( Updated at: 21 Dec 2023, 09:20 )

RE:

eOs IT said:

Hello everyone. This is my first speech on this forum. I hope I have written in the correct section and get a valid help.

Unfortunately I have two problems. One with a bot and one with an indicator.
I've been searching for solutions on the forum and on the Internet for weeks. Without success.
All the two codes are in Mql and have been successfully translated on 2calgo.com. 

The bot takes 1 to 3 seconds before it starts working (maybe because of about 3000 lines of code after translation) and I'm a scalper. Impossible to use.
An example: I have open operations. Three buy and two sell. 4 operations are winners and one a loser. Manually and in the shortest possible time (from a bot placed in a small detached window), I have to close all five operations at the same time (one after the other I know).

This is the original code:

int start()
{
   for (int i = (OrdersTotal() - 1); i >= 0; i--)
   {
      if      (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
      else if (OrderType() == OP_BUY)  OrderClose(OrderTicket(), OrderLots(), Bid, 0, Blue);
      else if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, 0, Blue);
   }
      return(0);
}


Instead, the indicator works correctly, but REVERSES the signal and is unusable.

 

This is the original code:

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 DarkBlue
#property indicator_color2 Maroon
extern int BarWidth = 4;
extern int       MACD_Fast=12;
extern int       MACD_Slow=20;
extern int       MACD_Signal=5;
extern int       Back_Bars=100;
extern bool      Set_Levels=true;
double Power_Buffer_Pos[];
double Power_Buffer_Neg[];
int init()
 {
   SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,BarWidth);
   SetIndexBuffer(0,Power_Buffer_Pos);
   SetIndexDrawBegin(0, Back_Bars);
   SetIndexLabel(0, NULL);
   SetIndexLabel(1, NULL);
   SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,BarWidth);
   SetIndexBuffer(1,Power_Buffer_Neg);
   SetIndexDrawBegin(1, Back_Bars);
   IndicatorShortName("");
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
   {
   int Bar_Index=0;
   int Pos_Bar_Count=0;
   int Neg_Bar_Count=0;
   double Total_Pos_Power=0;
   double Average_Pos_Power=0;
   double Total_Neg_Power=0;
   double Average_Neg_Power=0;
   int counted_bars=IndicatorCounted();
   for (Bar_Index = Back_Bars; Bar_Index >=0; Bar_Index--)
      {
      double MACD_Main = iMACD(Symbol(),0,MACD_Fast,MACD_Slow,MACD_Signal,PRICE_CLOSE,MODE_MAIN,Bar_Index);
      double MACD_Signal1 = iMACD(Symbol(),0,MACD_Fast,MACD_Slow,MACD_Signal,PRICE_CLOSE,MODE_SIGNAL,Bar_Index);
      double MACD_Diff = MACD_Main - MACD_Signal1;
     if (MACD_Diff > 0)
         {
         Power_Buffer_Pos[Bar_Index] = MACD_Diff;
         Power_Buffer_Neg[Bar_Index] = 0;
         Pos_Bar_Count = Pos_Bar_Count + 1;
         Total_Pos_Power = Total_Pos_Power +  MACD_Diff;
         }
      else if (MACD_Diff < 0)
         {
         Power_Buffer_Pos[Bar_Index] = 0;
         Power_Buffer_Neg[Bar_Index] = MACD_Diff;
         Neg_Bar_Count = Neg_Bar_Count + 1;
         Total_Neg_Power = Total_Neg_Power + MACD_Diff;
         }
      else if (MACD_Diff == 0)
         {
         Power_Buffer_Pos[Bar_Index] = 0;
         Power_Buffer_Neg[Bar_Index] = 0;
         }}
   Average_Pos_Power = Total_Pos_Power/Pos_Bar_Count;
   Average_Neg_Power = Total_Neg_Power/Neg_Bar_Count;
   if (Set_Levels == true)
      {
      SetLevelStyle( EMPTY, 1, C'20,20,20');
      SetLevelValue(1, Average_Pos_Power);
      SetLevelValue(2, Average_Neg_Power);
      }
   else if (Set_Levels == false)
      {
      SetLevelStyle( EMPTY, 1, C'20,20,20');
      SetLevelValue(1, 0);
      SetLevelValue(2, 0);
      }
   return(0);
   }


Can anyone help me kindly? Thank you.

 


@eOs IT

PanagiotisCharalampous
03 Jul 2018, 10:36

Hi eOs IT,

Thanks for posting in our forum. However, I don't think there is enough information for somebody to help you. First of all, you only posts parts of the code so it is not easy for somebody to understand what is going on. Also, how did you make the conversion? Did somebody convert the algorithms for you?

Best Regards,

Panagiotis


@PanagiotisCharalampous

eOs IT
03 Jul 2018, 12:06

RE:

Panagiotis Charalampous said:

Hi eOs IT,

Thanks for posting in our forum. However, I don't think there is enough information for somebody to help you. First of all, you only posts parts of the code so it is not easy for somebody to understand what is going on. Also, how did you make the conversion? Did somebody convert the algorithms for you?

Best Regards,

Panagiotis

Thank you for your attention Panagiotis. Sorry for my very long posts. I also regret that my request is not clear. The problem is certainly a non-perfect translation of Google translator.

- The two codes are not mine (all credit off to the original programmers).
- Both codes (as they are) are correctly converted from Mql to Ex4 with the last Metaeditor. They work perfectly and / or are displayed well in Mt4.
- Both codes (as they are) have been translated via the website: 2calgo.com. They result to be error free and properly functioning in cTrader.

The "problems" I find are:
For the Bot, activation after 2-3 seconds (and not immediately or almost).
For the indicator, the graphic video signal is inverted (histogram rising instead of falling and falling instead of rising) and I can not understand and find the problem in almost 3000 lines of code that 2calgo.com has produced.

Solutions:
For the Bot: I found on this Forum codes for cAlgo that in a dozen rows close all open orders (buy and sell win and loss) BUT CONDITIONED TO AN EVENT (achievement of a goal of gain or loss). I tried to modify them without success. I want orders to be closed IMMEDIATELY it does not matter if they are buy or sell, win or loss or any of these combinations if the orders are multiple (more than one).

For the Indicator: (if possible) the identification of the problem that the translation of the code on 2calgo.com causes the inversion of the signal (histogram rises instead of descending and falling instead of rising). Only a person familiar with code (who knows the logic with which 2calgo.com translates the code) could find the error and tell me.

Thanks in advance, to all those who can help me.
Enrico

 


@eOs IT

PanagiotisCharalampous
03 Jul 2018, 12:19

Hi Enrico,

Thanks for the additional information. First of all we do not have the cBot/Indicator code. Also we do not know what the cBot/Indicator are supposed to do in the first place. Therefore there is not much advice we can give. From your description we can also conclude that this will need some investigation so maybe you could consider contacting a professional cAlgo programmer to help you and maybe converting the EA and indicator for you instead of relying on an online tool.

Best Regards,

Panagiotis


@PanagiotisCharalampous