Horizontal Line not showing on Strategy Tester

danielfersbeanto
29

I put some horizontal line for High, Low and Middle line  and it can be show when I put it on the chart. But seems the horizontal line not showing when I did the Strategy tester so I can't really evaluate my strategy fully

My analogy on this is if you still play in the range it will be okay, but if the play getting more dangerous, please use condom (the SL) LOL

I have some condition when trade near the high line and low line to put some stop loss,I can see the stop loss happen but I don't know if those the ask or bid price on the range of those line because I can't see those lines

   double EMA1Array[];
   
   int EMA1Definition = iMA(_Symbol,_Period,1,0,MODE_EMA,PRICE_CLOSE); 
  
   ArraySetAsSeries(EMA1Array,true);      
   CopyBuffer(EMA1Definition,0,0,48,EMA1Array);      
    
   int max= ArrayMaximum(EMA1Array,0,WHOLE_ARRAY);    
   double maxClose =EMA1Array[max];
   int low= ArrayMinimum(EMA1Array,0,WHOLE_ARRAY);      
   double lowClose =EMA1Array[low];
   
   double avgValue = ((EMA1Array[max]+EMA1Array[low])/2); 

      string HCLine ="HCLine";
      ObjectCreate(0,HCLine,OBJ_HLINE,0,0,maxClose); 
      ObjectSetInteger(0,HCLine,OBJPROP_COLOR,clrRed);
   
      string LCLine ="LCLine";
      ObjectCreate(0,LCLine,OBJ_HLINE,0,0,lowClose); 
      ObjectSetInteger(0,LCLine,OBJPROP_COLOR,clrLime);
   
      string AVGLine ="AVGLine";
      ObjectCreate(0,AVGLine,OBJ_HLINE,0,0,avgValue);   
      ObjectSetInteger(0,AVGLine,OBJPROP_COLOR,clrYellow); 
//sell (this is the part where I put the stop loss for the trade based on those lines)

                     if (((AllCTrend[0] =="SELL") ||(AllCTrend[0] =="REVERSAL DOWN"))
                     &&  ((EMATrendArray[0]=="SELL") || (EMATrendArray[0] =="RD ON HV") || (EMATrendArray[0] =="REVERSAL DOWN")))                                                                   
                                 {   
                                 if(Bid<=(lowClose + (range*0.08)*_Point)) 
                                    {     
                                    trade.Sell(lotsize,NULL,Bid,Bid+500*_Point,0,NULL);                                                                                                       
                                    }  
                                 else
                                    {     
                                    trade.Sell(lotsize,NULL,Bid,0,0,NULL);                                                                                                       
                                    }  
                                 }   
                     //buy
                     else if (((AllCTrend[0] =="BUY") ||(AllCTrend[0] =="REVERSAL UP"))
                          &&  ((EMATrendArray[0]=="BUY") || (EMATrendArray[0] =="RU ON LV") || (EMATrendArray[0] =="REVERSAL UP")))
                                    {
                                    if(Ask>=(maxClose - (range*0.08)*_Point))
                                       {
                                       trade.Buy(lotsize,NULL,Ask,Ask-500*_Point,0,NULL);
                                       }
                                    else
                                       {                                
                                       trade.Buy(lotsize,NULL,Ask,0,0,NULL);                                 
                                       }                               
                                    }

I am sorry if my code is not really efficient, cause I just learn MQL 5 for 2-3 days. I will appreciate if someone can show me the better declaration tough. Those  3 horizontal lines can be show on live chart

Right now I am testing the stop loss condition on my development stage, I can see the open position with stop loss but the problem is just can't review it in visual mode with lines

Thanks In advance for some help

Daniel

Vladimir Karputov
Moderator
270369

1. Correct your mistake:

 int EMA1Definition = iMA(_Symbol,_Period,1,0,MODE_EMA,PRICE_CLOSE); 

you create an indicator handle at every tick! REMEMBER: The MQL5 style implies that the indicator handle is created ONCE and must be done in OnInit.

danielfersbeanto
29
danielfersbeanto  
Vladimir Karputov #:

1. Correct your mistake:

you create an indicator handle at every tick! REMEMBER: The MQL5 style implies that the indicator handle is created ONCE and must be done in OnInit.

Thanks, did you have some links for all of this kind of best practice MQL5 

Because I learn by myself on Youtube and I am not say that the video I watch is a bad tutor/teacher. But Probably this kind of rules must be in the introduction of how to programming in the right ways. Like my old always boss said "Do the right thing  first for the first time and every time"

===

Back to the point, strategy tester sometimes can shows the horizontal lines on rarely occassions. but not like in the live chart when I put data of like 20 charts, the lines is dynamically change when the high and low changes

But it show as static lines in visual mode, even after days of simulations and the price already goes above or below