8 hour price breakout error

 

Could someone look over this piece of code and see if they notice what the problem is? I keep getting error 4107 and 130.

What I am trying to do is to have it set a pending order using the high and low from the past 8 hours. Thanks for the help.

void CheckForOpen()
{
double TP_BuyLevel, SL_BuyLevel, Step_BuyLevel;
double TP_SellLevel, SL_SellLevel, Step_SellLevel;
double Max_Price, Min_Price;
int res;
if (CalculateCurrentOrders(Symbol())==0)
{
RefreshRates();
Max_Price=NormalizeDouble(iHigh(Symbol(),480,1),Digits);
if (TP==0) TP_BuyLevel=0; else TP_BuyLevel=NormalizeDouble(Max_Price+((TP+Step)*Point),Digits);
if (SL==0) SL_BuyLevel=0; else SL_BuyLevel=NormalizeDouble(Max_Price-((SL-Step)*Point),Digits);
Step_BuyLevel=NormalizeDouble(Max_Price+(Step*Point),Digits);
res=OrderSend(Symbol(),OP_BUYSTOP,LotsOptimized(),Step_BuyLevel,10,SL_BuyLevel,TP_BuyLevel,"",MAGICMA,0,CLR_NONE);
if (res==-1) Print("LastError = ",GetLastError());

RefreshRates();
Min_Price=NormalizeDouble(iLow(Symbol(),480,1),Digits);
if (TP==0) TP_SellLevel=0; else TP_SellLevel=NormalizeDouble(Min_Price-((TP+Step)*Point),Digits);
if (SL==0) SL_SellLevel=0; else SL_SellLevel=NormalizeDouble(Min_Price+((SL-Step)*Point),Digits);
Step_SellLevel=NormalizeDouble(Min_Price-(Step*Point),Digits);
res=OrderSend(Symbol(),OP_SELLSTOP,LotsOptimized(),Step_SellLevel,10,SL_SellLevel,TP_SellLevel,"",MAGICMA,0,CLR_NONE);
if (res==-1) Print("LastError = ",GetLastError());
}
return;

}


Thanks

 

have u created an 8 hour chart ?

& 4 the next time please use SRC 4 code


 
saricha3:

Could someone look over this piece of code and see if they notice what the problem is? I keep getting error 4107 and 130.

What I am trying to do is to have it set a pending order using the high and low from the past 8 hours. Thanks for the help.

<REMOVED>


Please use the SRC button to post code . . .
 

As Gjol says, there is no such thing as an 8 hour TF

Max_Price=NormalizeDouble(iHigh(Symbol(),480,1),Digits); 

Will return 0

 
Don't hard code numbers, use the enumerations
 

Thanks for the responses. Sorry about not using the SRC button.

I don't have the option for PERIOD_H8. I changed it to 4 hours.

Is there are a way to change this to easily change this one line to use the high of the last two periods. Or do I need to write it as an if statement that will compare the high of the last two 4 hour periods and take the highest of the two.


Max_Price=NormalizeDouble(iHigh(Symbol(),PERIOD_H4,1),Digits);
 
Max_Price=NormalizeDouble(iHigh(Symbol(),PERIOD_H4,iHighest(Symbol(),PERIOD_H4,MODE_HIGH,2,1)),Digits);
 

past eight hours

use PERIOD_H1 in calculation like GumRai showed

 
saricha3:

What I am trying to do is to have it set a pending order using the high and low from the past 8 hours. Thanks for the help.


saricha3:

I don't have the option for PERIOD_H8. I changed it to 4 hours.

Is there are a way to change this to easily change this one line to use the high of the last two periods. Or do I need to write it as an if statement that will compare the high of the last two 4 hour periods and take the highest of the two.


deVries:

past eight hours

use PERIOD_H1 in calculation like GumRai showed

Hmm, yes, not clear exactly what Saricha wants

Of course, for the last complete 8 x 1 hour bars, it would be

Max_Price=NormalizeDouble(iHigh(Symbol(),PERIOD_H1,iHighest(Symbol(),PERIOD_H1,MODE_HIGH,8,1)),Digits);
 
Last 8 hours is not the same as last two H4 bars.
iHigh(Symbol(),PERIOD_H1,iHighest(Symbol(),PERIOD_H1,MODE_HIGH,8,1)

iHigh(Symbol(),PERIOD_M1,iHighest(Symbol(),PERIOD_M1,MODE_HIGH,480,1); // Or
Last 2 H4 bars
iHigh(Symbol(),PERIOD_H4,iHighest(Symbol(),PERIOD_H4,MODE_HIGH,2,1)

MathMax( iHigh(Symbol(),PERIOD_H4, 1), 
         iHigh(Symbol(),PERIOD_H4, 2) ); // or
Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it.It's use is always wrong
Reason: