How to draw a trendline from price A until price B. But only when price B has a broken the low of price A.
elusivone:
This is my draw function:
the OBJ_TREND is anchored from time and candleLowPrice to time_to. time_to is hard coded as you can see when I call the draw function I have to pass the time to which the trendline stops. But I would like the trendline to stop at the candle before the candle that has a lower low than the first candle on which I anchored by trendline. How could I modify my code to do that?Your question seems interesting but to receive help on this forum you should post full source code.
Amos Tsopotsa #:
Post full source code so we can help
Post full source code so we can help
// -- Enum for the Swing Point Type -- // enum ENUM_SWING_TYPE { SWING_HIGH, SWING_LOW }; // -- Swing Points Class -- // class CSwingPoints { public: ENUM_SWING_TYPE type; datetime time; // Individual candle high price variable -- // double candleHighPrice; // Individual candle low price variable -- // double candleLowPrice; // -- Function to draw Swing Low on the chart -- // void DrawSwingLow(datetime time_to){ string objName = "Swing Low "+TimeToString(time); if(ObjectFind(0,objName) < 0){ ObjectCreate(0,objName,OBJ_TREND,0,time,candleLowPrice,time_to,candleLowPrice); ObjectSetInteger(0,objName,OBJPROP_COLOR, clrGreen); } } // -- Function to draw Swing High on the chart -- // void DrawSwingHigh(datetime time_to){ string objName = "Swing High "+TimeToString(time); if(ObjectFind(0,objName) < 0){ ObjectCreate(0,objName,OBJ_TREND,0,time,candleHighPrice,time_to,candleHighPrice); ObjectSetInteger(0,objName,OBJPROP_COLOR, clrRed); } } }; void OnDeinit(const int reason){ ObjectsDeleteAll(0,"Swing Low"); ObjectsDeleteAll(0,"Swing High"); } int OnInit(){ return(INIT_SUCCEEDED); } int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]){ ArraySetAsSeries(time,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); int bars_for_loop = rates_total - prev_calculated; if(bars_for_loop > rates_total - 2) bars_for_loop = rates_total - 3; // Loop through the candles to plot swing highs for(int i = bars_for_loop; i >= 1; i--){ // -- Candles are calculated from the right to the left -- // double candleOneHigh = high[i]; double candleTwoHigh = high[i + 1]; double candleThreeHigh = high[i + 2]; bool isSwingHigh = candleOneHigh < candleTwoHigh && candleTwoHigh > candleThreeHigh; if(isSwingHigh){ CSwingPoints swingHigh; swingHigh.type = SWING_HIGH; swingHigh.time = time[i + 1]; swingHigh.candleHighPrice = candleTwoHigh; swingHigh.DrawSwingHigh(time[i] + PeriodSeconds(PERIOD_CURRENT) * 5); } } // Loop through the candles to plot swing lows for(int i = bars_for_loop; i >= 1; i--){ // -- Candles calculated from the right to the left -- // double candleOneLow = low[i]; double candleTwoLow = low[i + 1]; double candleThreeLow = low[i + 2]; bool isSwingLow = candleOneLow > candleTwoLow && candleTwoLow < candleThreeLow; if(isSwingLow){ CSwingPoints swingLow; swingLow.type = SWING_LOW; swingLow.time = time[i + 1]; swingLow.candleLowPrice = candleTwoLow; swingLow.DrawSwingLow(time[i] + PeriodSeconds(PERIOD_CURRENT) * 5); } } return(rates_total); }
Arpit T #:
Your question seems interesting but to receive help on this forum you should post full source code.
// -- Enum for the Swing Point Type -- // enum ENUM_SWING_TYPE { SWING_HIGH, SWING_LOW }; // -- Swing Points Class -- // class CSwingPoints { public: ENUM_SWING_TYPE type; datetime time; // Individual candle high price variable -- // double candleHighPrice; // Individual candle low price variable -- // double candleLowPrice; // -- Function to draw Swing Low on the chart -- // void DrawSwingLow(datetime time_to){ string objName = "Swing Low "+TimeToString(time); if(ObjectFind(0,objName) < 0){ ObjectCreate(0,objName,OBJ_TREND,0,time,candleLowPrice,time_to,candleLowPrice); ObjectSetInteger(0,objName,OBJPROP_COLOR, clrGreen); } } // -- Function to draw Swing High on the chart -- // void DrawSwingHigh(datetime time_to){ string objName = "Swing High "+TimeToString(time); if(ObjectFind(0,objName) < 0){ ObjectCreate(0,objName,OBJ_TREND,0,time,candleHighPrice,time_to,candleHighPrice); ObjectSetInteger(0,objName,OBJPROP_COLOR, clrRed); } } }; void OnDeinit(const int reason){ ObjectsDeleteAll(0,"Swing Low"); ObjectsDeleteAll(0,"Swing High"); } int OnInit(){ return(INIT_SUCCEEDED); } int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]){ ArraySetAsSeries(time,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); int bars_for_loop = rates_total - prev_calculated; if(bars_for_loop > rates_total - 2) bars_for_loop = rates_total - 3; // Loop through the candles to plot swing highs for(int i = bars_for_loop; i >= 1; i--){ // -- Candles are calculated from the right to the left -- // double candleOneHigh = high[i]; double candleTwoHigh = high[i + 1]; double candleThreeHigh = high[i + 2]; bool isSwingHigh = candleOneHigh < candleTwoHigh && candleTwoHigh > candleThreeHigh; if(isSwingHigh){ CSwingPoints swingHigh; swingHigh.type = SWING_HIGH; swingHigh.time = time[i + 1]; swingHigh.candleHighPrice = candleTwoHigh; swingHigh.DrawSwingHigh(time[i] + PeriodSeconds(PERIOD_CURRENT) * 5); } } // Loop through the candles to plot swing lows for(int i = bars_for_loop; i >= 1; i--){ // -- Candles calculated from the right to the left -- // double candleOneLow = low[i]; double candleTwoLow = low[i + 1]; double candleThreeLow = low[i + 2]; bool isSwingLow = candleOneLow > candleTwoLow && candleTwoLow < candleThreeLow; if(isSwingLow){ CSwingPoints swingLow; swingLow.type = SWING_LOW; swingLow.time = time[i + 1]; swingLow.candleLowPrice = candleTwoLow; swingLow.DrawSwingLow(time[i] + PeriodSeconds(PERIOD_CURRENT) * 5); } } return(rates_total); }

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
This is my draw function:
the OBJ_TREND is anchored from time and candleLowPrice to time_to. time_to is hard coded as you can see when I call the draw function I have to pass the time to which the trendline stops. But I would like the trendline to stop at the candle before the candle that has a lower low than the first candle on which I anchored by trendline. How could I modify my code to do that?