Download MetaTrader 5

Check previous 10 candles/bars and determine the lowest close price

To add comments, please log in or register
Gerardo Bustos
745
Gerardo Bustos  

Hello forum, good day.

How could I make a function that checks the previous 10 candles/bars and determine the lowest close price of those candles/bars? After this I need to check if Close[0] < LowestClose and then assign StopLoss = AskPrice;

Best regards and thank you,

codeMolecules 

Alexander Puzanov
34813
Alexander Puzanov  
codeMolecules:

How could I make a function that checks the previous 10 candles/bars and determine the lowest close price of those candles/bars?

MQL4 ?

double d_Lowest_Close = Low[iLowest(_Symbol, PERIOD_CURRENT, MODE_CLOSE, 10, 1)];
Gerardo Bustos
745
Gerardo Bustos  
f2011:

MQL4 ?

Hello f2011, good day.

Yes, in MQL4. I´ll give it a try. Thank you very much!!

Best regards,

codeMolecules 

Gerardo Bustos
745
Gerardo Bustos  
codeMolecules:

Hello f2011, good day.

Yes, in MQL4. I´ll give it a try. Thank you very much!!

Best regards,

codeMolecules 

I came up with this:


double CalcStopLoss()
  {
    double sl;
    double LowestClose  = Low[iLowest( NULL, 0, MODE_CLOSE, 10, 1 )];
    double HighestClose = Low[iHighest( NULL, 0, MODE_CLOSE, 10, 1 )];

    if ( Close[0] < LowestClose ) sl = Ask; //--- Buy Stop Loss
    else if ( Close[0] > HighestClose ) sl = Bid; //--- Sell Stop Loss

    return( sl );
  }


I add CalcStopLoss() at the Stop Loss argument in the OrderSend() function, but I get an OrderSend error 130, why is this?

 

Best regards and thank you,

codeMolecules 

Alexander Puzanov
34813
Alexander Puzanov  
double HighestClose = Low[iHighest( NULL, 0, MODE_CLOSE, 10, 1 )];

It is better to use syntax from modern versions of MQL4. Then do not have to re-write your codes soon + these designations is much easier to read and understand

 

double HighestClose = Low[iHighest( NULL, 0, MODE_CLOSE, 10, 1 )];

Typo? Must be High

 

if ( Close[0] < LowestClose ) sl = Ask; //--- Buy Stop Loss

else if ( Close[0] > HighestClose ) sl = Bid; //--- Sell Stop Loss

1. Do not forget that Buy-orders closes at Bid-prices, Sell-orders at Ask-prices
2. Maybe SL is too close to order open price?

 

I add CalcStopLoss() at the Stop Loss argument in the OrderSend() function

Don't forget about NormalizeDouble(CalcStopLoss(), _Digits)

PS: double sl = 0;

Gerardo Bustos
745
Gerardo Bustos  
f2011:

It is better to use syntax from modern versions of MQL4. Then do not have to re-write your codes soon + these designations is much easier to read and understand

 

Typo? Must be High

 

1. Do not forget that Buy-orders closes at Bid-prices, Sell-orders at Ask-prices
2. Maybe SL is too close to order open price?

 

Don't forget about NormalizeDouble(CalcStopLoss(), _Digits)

Thank you very much f2011!!

Best regards,

codeMolecules 

To add comments, please log in or register