Buy order problems

 

this bit of code doesnt seem to buy, any ideas why?

if(Close[2]ma)

{

OrderSend(Symbol(),OP_BUY,lots,Ask,3,stop,Ask+profit,"",2005,0,Green);

}

it should buy when a new candle closes above the moving average and the previous closed below it.

 
trevman2005:
this bit of code doesnt seem to buy, any ideas why?
if(Close[2]ma)

{

OrderSend(Symbol(),OP_BUY,lots,Ask,3,stop,Ask+profit,"",2005,0,Green);

}
it should buy when a new candle closes above the moving average and the previous closed below it.

I think it should be:

if(Close[1]ma)

{

ticket=OrderSend(Symbol(),OP_BUY,lots,Ask,3,stop*Point,Ask+profit*Point,"",2005,0,Green);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))

Print("BUY order opened : ",OrderOpenPrice());

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}
 

that worked, very much appreciated, but why the "ticket", "orderselect" and "Point" x ask+profit?, i'm reading through your tutorials atm, i apologise if i missed this info. thanks again.

 

You're welcome!

trevman2005:
that worked, very much appreciated, but why the "ticket" and "orderselect" i'm reading through your tutorials atm, i apologise if i missed this info. thanks again.
You're welcome!
If you noticed the code:
1- I've changed
if(Close[2]<ma&&Close[1]>ma)
To:
if(Close[1]<ma&&Close[0]>ma)
Because the index of the new bar is 0 and the index of the previous one is 1.
2- I used ticket and OrderSelect only to check what the wrong (if any) is. (Please prefer toAppendix 2 - Trading functions)
3- I've changed stop to stop*Point and profit to profit*Point.
 
codersguru:
3- I've changed stop to stop*Point and profit to profit*Point.[/left]

why does point need to be a part of the code?

i've also noticed that my stoploss is set to 30 and my take profit is 80, yet my backtest results give me around 17 loss and 45 profit, why does it do this? thanks again.

 

Point

trevman2005:
why does point need to be a part of the code?

Pointfunction returns the point size of the current symbol.

(EX: if you trade EURUSD the point value = .0001 and if you trade EURJPY the point value should be .01)

So, if your stoplossmust be converted to points in order to use OrderSendor OrderModifyfunctions.

i've also noticed that my stoploss is set to 30 and my take profit is 80, yet my backtest results give me around 17 loss and 45 profit, why does it do this? thanks again.

Could you explain more? Do you mean that the strategy tester automatically set your stoploss and takeprofit values?

 
codersguru:
Pointfunction returns the point size of the current symbol.

(EX: if you trade EURUSD the point value = .0001 and if you trade EURJPY the point value should be .01)

So, if your stoplossmust be converted to points in order to use OrderSendor OrderModifyfunctions.

"Ask+profit*Point" should be equal to whatever i set my profit level at right?, but if "ask" is 1.1825 and "profit" is 50 then "1.1825+80*1.1825" but that equals 95

codersguru:
Could you explain more? Do you mean that the strategy tester automatically set your stoploss and takeprofit values?

my expert has the below settings as default

extern double profit = 80;

extern double stop = 30;

but backtesting produced t/p stops of 45-46 and stoploss losses of 17

 
trevman2005:
"Ask+profit*Point" should be equal to whatever i set my profit level at right?, but if "ask" is 1.1825 and "profit" is 50 then "1.1825+80*1.1825" but that equals 95

No, the Point will be .0001 not 1.1825 (1.1825 is the ask price).

So,

If "ask" is 1.1825 and "profit" is 50then:

1.1825 + (50 * .0001) = 1.1825 + 0.005 = 1.1875 (50 Pips)

my expert has the below settings as default

extern double profit = 80;

extern double stop = 30;

but backtesting produced t/p stops of 45-46 and stoploss losses of 17

Still don't understand this point .

Did you use Optimizationtesting mode?

 

maybe this will help,

Parameters profit=80; stop=30;

yet niether the t/p or s/l are the same as the specified

Files:
 

does no one have any ideas why the results are as shown in the test run?

Reason: