Hi, how do I test the last loss-position type something like…?
If PositionPerf(1) < 0 and OnMarket[1]=1 Then
Do you want to know if the last loser was a SELLSHORT or a BUY?
But only the last position? Or could it be a position far away in the orders history?
In this case, why do not save in a variable the type of the order you are launching at market:
if BuyCondition then
BUY 1 CONTRACT AT MARKET
ordertype = 1 //it's a buy order !
endif
if SellCondition then
SELLSHORT 1 CONTRACT AT MARKET
ordertype = -1 //it's a sell order !!
endif
Indeed, I thought of that, I wondered if there was another way.
Thanks.
Hi, I want to know the same thing but I’m using a stop order.
I this case I don’t know when the order will be triggered in and I’m placing a short and a long order at the same time.
I’m interested to find out what order was closed. if one of the orders is closed (winner), the other order that was not triggered needs to be removed (not renewed).
Thanks
You know what price you placed the orders at so just check to see if a high or low was above or below those prices. You may have to include a fudge factor for spread which adds some inaccuracy to the whole thing though.
Little code snippet to check the profit of the last order and its direction:
//------------------
//check profit
if strategyprofit<>strategyprofit[1] then
if positionperf(1)>0 then
if close<tradeprice(2) then
gain=-1 //was sell
elsif close>tradeprice(2) then
gain=1 //was buy
endif
else
gain=0
endif
endif