Hi,
I'm trying to convince my code to close a trade when a bar closes above the MA and somehow, I've managed to mess it up and I'm not sure where or how
I need fresh eyes as I've already gone insane over it
Here's the function for closing a buy trade when a bar closes above the Ma (I would like to have a bit more fancy conditions but since it doesn't close at all, let's start with something simple)
Calling the function (idealy, I'd like to call the function to close either buy or sell orders but here is a simplified version of it)
The code itself, I know it's a bit messy from all my failed attempts at debugging it
A screen shot of a trade on the Strategy Tester with the output from the Journal tab, Close[barRange] is bigger than DwMaFast and barRange is 1 so why isn't it entering the cooresponding if statement?
Thanks
I'm trying to convince my code to close a trade when a bar closes above the MA and somehow, I've managed to mess it up and I'm not sure where or how
I need fresh eyes as I've already gone insane over it
Here's the function for closing a buy trade when a bar closes above the Ma (I would like to have a bit more fancy conditions but since it doesn't close at all, let's start with something simple)
Calling the function (idealy, I'd like to call the function to close either buy or sell orders but here is a simplified version of it)
Inserted Code
MaClose(1, true);
The code itself, I know it's a bit messy from all my failed attempts at debugging it
Inserted Code
void MaClose(int barRange,bool toClose) { double DwMaFast = iMA(Symbol(),AllTimeFrame,DwFast,0,DwMethod,DwPrice,barRange); double DwMaSlow = iMA(Symbol(),AllTimeFrame,DwSlow,0,DwMethod,DwPrice,barRange); int ordercount = OpenedOrdersAll(); Alert("1: toClose: "+toClose+" ordercount: "+ordercount+" DwMaFast: "+DwMaFast+" DwMaSlow: "+DwMaSlow+" barRange: "+barRange+" Close[barRange]: "+Close[barRange]); if ( BuyMe && (ordercount > 0) && BuyMeEAMode ) { double DwMaFast = iMA(Symbol(),AllTimeFrame,DwFast,0,DwMethod,DwPrice,barRange); double DwMaSlow = iMA(Symbol(),AllTimeFrame,DwSlow,0,DwMethod,DwPrice,barRange); Alert("2: toClose: "+toClose+" DwMaFast: "+DwMaFast+" DwMaSlow: "+DwMaSlow+" barRange: "+barRange+" Close[barRange]: "+Close[barRange]); //if ( toClose && (Close[barRange] > DwFast) ) if (Close[barRange] > DwFast) { Alert("3: toClose: "+toClose+" DwMaFast: "+DwMaFast+" DwMaSlow: "+DwMaSlow+" barRange: "+barRange+" Close[barRange]: "+Close[barRange]); CloseOrders(toClose, TradeCommentFirstest); } } }
A screen shot of a trade on the Strategy Tester with the output from the Journal tab, Close[barRange] is bigger than DwMaFast and barRange is 1 so why isn't it entering the cooresponding if statement?
Thanks