Coding Problem - comparing two prices
-
Hello people I'm new to this software, and I have a problem thats giving me quite the headache...here's a statement of what I am trying to code:
The current trade signal should be compared to the last trade of the same direction (the current buy/sell signal is compared to the previous buy/sell trade), if that trade ended in profit or break-even, the current trade can be opened as per the (buy/sell) signal, but** if the trade was a loss (stop loss or direct loss) then, do not open the trade unless the current signals price is higher (for BUY signal)/lower (for SELL signal) than the previous trades’ entry price.**
I would appreciate any ideas and contribution. Thanks
-
This is not correct: http://prntscr.com/4kgpfz
Group mode is a string parameter with undocumented values, I will not recommend to use variables for this parameter and most of the drop-down (with multiple options) parameters.Otherwise I think you are doing it good. With "For each Closed Trade" you can load the last closed trade and do something with it. Note that when this block loads a trade, only pink blocks can be used to work with that particular trade. Other type of blocks can be used in the loop as well, but they work for themselves. For example, block 19 does not load the last buy trade for block 20, block 20 still works with the trade loaded in block 14.
Again, I will not recommend to use non-pink blocks under "For each...." block, but when needed - no problem.So, if your Buy was closed on loss, you don't want to open new Buy when the current price is higher than the open price of the losable closed Buy. But you will probably be ok with opening a new sell. Then, can we say that you want to just invert the next trade on loss? If the last losable trade was Buy - wait for Sell condition?
-
Or something like this: https://fxdreema.com/shared/hAdvsbOac
This is the result: http://prntscr.com/4kgw6pI used two variables, AllowBuy and AllowSell. They can have values 0 or 1. They are both set to 1 in block 2, and then depending on the last closed trade - one of them is set to 0.
Then, before buying/selling these are checked. -
Thanks for the education, you sure put a lot into fxdreema
I have modified the format based on your example and advice, it would be great if you could look through it and tell me if it functions like I described it in the template. Please also have a look at the 'onTrade' section. Any other advice to complete the EA is welcome. Also is it possible to know the right slippage number to use?