Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 811

 
Pomid:

Here we need to place pending orders and calculate their prices relative to the previous bar close price. BUYSTOP is placed, while SELLSTOP returns error 130. Is there an error in this code? Or in another function.

void SetOrders() {

  double ldStop=0, ldTake=0;
  int    spr=MarketInfo(Symbol(), MODE_SPREAD);
  double PredBar=iClose(NULL,PERIOD_M5,1);
  double pAsk=PredBar+(DistanceSet+spr)*Point;
  double pBid=PredBar-(DistanceSet+spr)*Point;

  if (!ExistOrder(1)) {
    if (StopLoss!=0) ldStop=pAsk-StopLoss*Point;
    if (TakeProfit!=0) ldTake=pAsk+TakeProfit*Point;
    SetOrder(OP_BUYSTOP, pAsk, ldStop, ldTake, 1);
  }
  if (!ExistOrder(2)) {
    if (StopLoss!=0) ldStop=PredBar+(StopLoss*Point);
    if (TakeProfit!=0) ldTake=pBid-TakeProfit*Point;
    SetOrder(OP_SELLSTOP, pBid, ldStop, ldTake, 2);
  }
}

Why don't you address the author? He's still alive and young, not old! The coordinates are in the code above each function! Everyone knows him and respects him!

And learn how to insert code like this, with SRC!

void SetOrders() {

  double ldStop=0, ldTake=0;
  int    spr=MarketInfo(Symbol(), MODE_SPREAD);
  double PredBar=iClose(NULL,PERIOD_M5,1);
  double pAsk=PredBar+(DistanceSet+spr)*Point;
  double pBid=PredBar-(DistanceSet+spr)*Point;

  if (!ExistOrder(1)) {
    if (StopLoss!=0) ldStop=pAsk-StopLoss*Point;
    if (TakeProfit!=0) ldTake=pAsk+TakeProfit*Point;
    SetOrder(OP_BUYSTOP, pAsk, ldStop, ldTake, 1);
  }
  if (!ExistOrder(2)) {
    if (StopLoss!=0) ldStop=PredBar+(StopLoss*Point);
    if (TakeProfit!=0) ldTake=pBid-TakeProfit*Point;
    SetOrder(OP_SELLSTOP, pBid, ldStop, ldTake, 2);
  }
}

You messed around with PredBar without understanding it, and that's the result! Learn the math first!

 
Good evening, could you please tell me how to solve the problem with the indicator not working on the new build. When compiling it gives error 'TotalOrders' - illegal switch expression type ( the error is highlighted in the code ). Regards, alexander.
 for (i=0; i<k; i++)
   {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) 
    {
      if ((OrderSymbol()==Symb) && (OrderType()==op))
        {
            ko++;
            TotalOrders[ChartListPosition+1][ko][1]=NormalizeDouble(OrderOpenPrice(),dig);
            TotalOrders[ChartListPosition+1][ko][2]=NormalizeDouble(OrderStopLoss(),dig);
            TotalOrders[ChartListPosition+1][ko][3]=NormalizeDouble(OrderTakeProfit(),dig);
            TotalOrders[ChartListPosition+1][ko][4]=OrderTicket();
            TotalOrders[ChartListPosition+1][ko][5]=OrderLots();
            TotalOrders[ChartListPosition+1][ko][6]=OrderType();
            TotalOrders[ChartListPosition+1][ko][7]=OrderMagicNumber();
            TotalOrders[ChartListPosition+1][0][0]=ko;
           
              switch(TotalOrders[ChartListPosition+1][ko][6])
              {
               case OP_BUY:
                        Type="Buy";
                break;
                
               case OP_BUYSTOP:
                        Type="Buy Stop";

 for(int j=1;j<=OrdersCount;j++)  
      {
       
         switch(TotalOrders[ChartsListPosition+1][j][6])
          {
           case OP_SELL: 
               if (TotalOrders[ChartsListPosition+1][j][2]!=0 && 
                   ask>=(TotalOrders[ChartsListPosition+1][j][2]-NormalizeDouble(StopLevel*point,dig)))  
                   {
                    test=StopLossColor;
                   } 
                   else
                   {
                   if (TotalOrders[ChartsListPosition+1][j][3]!=0 && 
                       ask<=(TotalOrders[ChartsListPosition+1][j][3]+NormalizeDouble(StopLevel*point,dig)))
                      {
                       test=TakeProfitColor;
                      }
                   }
             break;       
 
karwin:
Good evening, could you please tell me how to solve the problem with the indicator not working on the new build. When compiling it gives error 'TotalOrders' - illegal switch expression type (the error is highlighted in the code). Regards, alexander.

The variable should be there, not something else:

              int Переменная=TotalOrders[ChartListPosition+1][ko][6];
              switch(Переменная)
              {
               case OP_BUY:
                        Type="Buy";
                break;
                
               case OP_BUYSTOP:
                        Type="Buy Stop";
 

Hello comrades.

Can you advise me, I'm not very familiar with MT5, I've hardly ever used it, while testing only one CPU core is engaged, I have 8 of them, why is that? How do I fix it?


 
7Konstantin7:

Hello comrades.

Can you advise me, I'm not very familiar with MT5, I've hardly ever used it, while testing only one CPU core is engaged, I have 8 of them, why is that? How do I fix it?


You should ask in the fifth forum
 
7Konstantin7:

Hello comrades.

Can you advise me, I'm not very familiar with MT5, I've hardly ever used it, while testing only one CPU core is engaged, I have 8 of them, why is that? How do I fix it?


Is it so for testing or for optimization? If just testing - one core works, but if you enable "Optimize" option in the strategy tester, all cores of the processor will work.
 
borilunad:

You messed around with PredBar without understanding, that's the result! Learn the math first!

Thank you, learned it, corrected it.
 
evillive:
you should ask about it on the fifth forum

"I'm not a member of the site, that's why I asked the question here.

barabashkakvn:
Is that during testing or optimizing? If you just test - one core works, but when you turn on the option "Optimize" in the strategy tester, will run all the cores of the processor.

I have understood everything, thank you all. During the test one core is working and everything is working as it should be,

I can't understand why they didn't just use the full power of the processor in the test.

 
7Konstantin7:

"I'm not a member of the site, that's why I asked the question here.

I have understood everything, thank you all. During the test one core is working and everything is working as it should be,

I can't understand why they do not use all the power of the processor in testing.

And why should we load all the cores during testing (without optimization turned on)? After all, if testing with visualization, there is no hurry, and if testing without visualization - so modern computers perform this task like sunflower seeds on a single core.
 
Pomid:
Thanks, learned it, fixed it.
What a shot, you made it! But I can't learn, there's always a lot I don't know yet, and it keeps getting updated. So, "live and learn!"
Reason: