Question: 'fake trades'?

 

I finally managed to create the code I wanted, and learnt a huge deal from getting stats with it. Probably most importantly, that in about 2 months from now I would have wiped out my account (even though I am making money now). If only I started learning 15 years ago!

Now, I have this question. I am not asking for code, just some ideas on where to look to start coding what I envision next:


I need mt4 to 'pretend place' trades (in memory but not in actuality) and record how they turn out.

Then mt4 will wait for 5 such trades (or a certain occurance of trade turnouts) and then it will go live on lets say the 6th trade if conditions from those 5 past pretend trades are met.


To make it simpler, like this:

mt4 pretend places a trade -> it's a loss -> it does it again -> it's a loss -> it does it again -> it's a loss...and so on for 5 consequitive losses

So, after 5 consequitive losses, it starts to enter live. (as an example)


1. How do I even go about coding something like this? (I'l code the rules, I don't know how to do the 'pretend/memory' part bit)

2. Is there code in codebase under some name that does something like this already (or something similar, that I can take appart myself)?


Please don't code anything for me, if you could just point me where I should go and look.

As always your help is super appreciated!

Thank you!

 

create a static integer, increment it by one each time a trade criteria becomes true, only allow trade for real when the integer == 5 and then reset the integer to zero.

Also when trade criteria becomes true, put current price in a static double, when trade exit condition becomes true, calculate the difference between the exit price and the first price to see if it is loss or profit.

 
Awesome! Thanks!
 
Got it thank you SDC!
 

How do I limit the incrementation?

It will start incrementing and won't stop as soon as the trade criteria becomes true, until it fails to be true

My trade criteria is simply for the price to be above price1 (price1 = priceat01.00hour(i.e. Ask)+20pips) (this would be the first 'fake buy' trade)

Then for every tick this is true it will increment 1 to the static, but I only want it to increment it once by 1

 

the same way you would have prevented it opening trade after trade every tick if it were real trades. Use a bool. When a trade is opened set it to true dont let it open any more while it is true.

 
thank you!
 

Guys, i'm a bit stuck, I did all that was needed, but now this problem:


bool buy11()
{
int i1=OrdersHistoryTotal()-1;
if(OrderSelect(i1,SELECT_BY_POS,MODE_HISTORY)==true)
OrderSend(Symbol(),OP_BUY,OrderLots()*1.2,Ask,3,Ask-StopLoss*pips,Ask+TakeProfit*pips,NULL,MagicNumber,0,Green);
GetLastError();
return(true);
} 


OrderLots()*1.2 = does not work

OrderLots()*2 = does work


How do I make it so the 1.2 works? (multiplying by 2 is too much for my MM, I need it to multiply by 1.2)

 
and then it can round it up to whatever is needed if that's what it needs to do to accept the lots (I just have no idea how to do that bit)
 
niko:
and then it can round it up to whatever is needed if that's what it needs to do to accept the lots (I just have no idea how to do that bit)
Your position size must be a multiple of LotStep, search and you will find code . . .
 

Thank you Raptor!

I did this:

OrderSend(Symbol(),OP_BUY,NormalizeDouble(OrderLots()*1.5,2),Ask,3,Ask-StopLoss*pips,Ask+TakeProfit*pips,NULL,MagicNumber,0,Green);

I know my broker's LotStep (it is 0.01), is the above ok to use then (so long as I don't switch brokers)?