You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello everyone
I use this code to draw SL and TP lines. I have two problems:
1) I can't continue the lines until Time < Time[i]; For Example : Time[i-10]
2) Each time the indicator signals, the previous lines are not deleted to be displayed for the next signal. But this happens when the timeframe of the chart is changed.
please guide me.
//--- My Code //--- My Code //--- My Code for(int i= MaxBars ; i>=0; i--) { //--- My Code //--- My Code //--- My Code //--- My Code //--- My Code //--- My Code //--- Buy Signals: if(BuySignal) { EntryPrice = Close[i+1]; StopLoss = EntryPrice - 2*iATR(NULL,0,Arr_Perod,0; TP1 = EntryPrice + (EntryPrice - StopLoss); TP2 = EntryPrice + 2*(EntryPrice - StopLoss); TP3 = EntryPrice + 3*(EntryPrice - StopLoss); if(Sl_TP) { TLineDelete(0,"EntryPrice"); TLineDelete(0,"StopLoss"); TLineDelete(0,"TP1"); TLineDelete(0,"TP2"); TLineDelete(0,"TP3"); } Buy_Arrow[i] = Low[i] - ArrowDisplacement*LMA_HMA; if(Show_SL_TP_Ray && Sl_TP > 0 ) { TLineCreate(0,"EntryPrice","EntryPrice",0,Time[i+10],EntryPrice,Time[i],EntryPrice,clrYellow,SL_TP_Style,Last_SL_TP_width,"EntryPrice = "+DoubleToString(EntryPrice,_Digits)); TLineCreate(0,"StopLoss","StopLoss",0,Time[i+10],StopLoss,Time[i],StopLoss,clrRed,SL_TP_Style,Last_SL_TP_width,"StopLoss = "+DoubleToString(StopLoss,_Digits)); TLineCreate(0,"TP1","TP1",0,Time[i+10],TP1,Time[i],TP1,clrGreen,SL_TP_Style,Last_SL_TP_width,"TP1 = "+DoubleToString(TP1,_Digits)); TLineCreate(0,"TP2","TP2" ,0,Time[i+10],TP2,Time[i],TP2,clrGreen,SL_TP_Style,Last_SL_TP_width,"TP2 = "+DoubleToString(TP2,_Digits)); TLineCreate(0,"TP3","TP3" ,0,Time[i+10],TP3,Time[i],TP3,clrGreen,SL_TP_Style,Last_SL_TP_width,"TP3 = "+DoubleToString(TP3,_Digits)); } } //--- Buy Signals End //--- My Code //--- My Code //--- My Code //--- My Code //--- My Code //--- My Code //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Create a trend line by the given coordinates | //+------------------------------------------------------------------+ bool TLineCreate(const long chart_ID=0, // chart's ID const string name="TrendLine", // line name const string text="Label", // Label const int sub_window=0, // subwindow index datetime time1=0, // first point time double price1=0, // first point price datetime time2=0, // second point time double price2=0, // second point price const color clr=clrRed, // line color const ENUM_LINE_STYLE style=STYLE_SOLID, // line style const int width=1, // line width const string tooltip="tooltip", // tooltip const bool back=true, // in the background const bool selection=false, // highlight to move const bool hidden=true, // hidden in the object list const long z_order=0) // priority for mouse click { ResetLastError(); if(!ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,time1,price1,time2,price2)) return(false); ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,Last_SL_TP_Ray); ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); ObjectSetString(chart_ID,name,OBJPROP_TOOLTIP,tooltip); return(true); } //+------------------------------------------------------------------+ //| Edit trend line | //+------------------------------------------------------------------+ bool TLineEdit(const long chart_ID=0, // chart's ID const string name="TrendLine", // line name datetime time1=0, // first point time const bool ray_right=false, // line's continuation to the right const ENUM_LINE_STYLE style=STYLE_DOT, // line style const bool hidden=true, // hidden in the object list const int width=1) // line width { ResetLastError(); if(!ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right)) return(false); if(!ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style)) return(false); if(!ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width)) return(false); if(!ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden)) return(false); return(true); } //+------------------------------------------------------------------+ //| The function deletes the trend line from the chart. | //+------------------------------------------------------------------+ bool TLineDelete(const long chart_ID=0, // chart's ID const string name="TrendLine") // line name { ResetLastError(); if(!ObjectDelete(chart_ID,name)) return(false); return(true); }