Download MetaTrader 5
To add comments, please log in or register
Added support for the Spanish language. Come and check it out!
John
17
John 2014.02.24 02:19 

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

qjol
3243
qjol 2014.02.24 02:31  

have u created an 8 hour chart ?

& 4 the next time please use SRC 4 code


Simon Gniadkowski
Moderator
17962
Simon Gniadkowski 2014.02.24 09:52  
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 . . .
Keith Watford
Moderator
7869
Keith Watford 2014.02.24 10:22  

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

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

Will return 0

whroeder1
13593
whroeder1 2014.02.24 14:24  
Don't hard code numbers, use the enumerations
John
17
John 2014.03.01 01:41  

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);
Keith Watford
Moderator
7869
Keith Watford 2014.03.01 03:24  
Max_Price=NormalizeDouble(iHigh(Symbol(),PERIOD_H4,iHighest(Symbol(),PERIOD_H4,MODE_HIGH,2,1)),Digits);
Tjipke de Vries
6275
Tjipke de Vries 2014.03.01 08:40  

past eight hours

use PERIOD_H1 in calculation like GumRai showed

Keith Watford
Moderator
7869
Keith Watford 2014.03.01 09:44  
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);
whroeder1
13593
whroeder1 2014.03.01 13:04  
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
/
To add comments, please log in or register