Override LotsOptimizer? - Keeps Scaling in Lots - MaxTrades code not working

 

This is something I have been struggling with for sometime. Because of the type of EA I am trying to use, I feel that scaling lot entrys

at different prices is somewhat better. I can't seem to make it stop or shut off the Maximum number of Lots or trades. Lot size control

is no problem. My account is a small one and until I can get some kind of control over the number of Lots or Open Orders, I can not turn

the EA loose. If it's not possible to use the LotsOptimizer together with a Maximum Trades control, then Static Lots or No LotsOptimizer

will at least get me going again. I know percent acct. risk or Margin alone won't do it. The EA I am attaching is not the one I am working

with but is similar.

JimsTradingMachine

Files:
 
jimtrader1:

This is something I have been struggling with for sometime. Because of the type of EA I am trying to use, I feel that scaling lot entrys

at different prices is somewhat better. I can't seem to make it stop or shut off the Maximum number of Lots or trades. Lot size control

is no problem. My account is a small one and until I can get some kind of control over the number of Lots or Open Orders, I can not turn

the EA loose. If it's not possible to use the LotsOptimizer together with a Maximum Trades control, then Static Lots or No LotsOptimizer

will at least get me going again. I know percent acct. risk or Margin alone won't do it. The EA I am attaching is not the one I am working

with but is similar.

JimsTradingMachine

The file is not correct. Try first to compile... and post again.
 
I haven't understood exactly, but if you are looking for lots calculating
/*****  does not work on indices, it is for forex only ******/
double LotsCalc ( string sy , double StopLoss = 0 , double AccountRisk = 1 ) {
 double funds = MathMin ( AccountBalance() , AccountEquity() );
   if ( AccountStopoutMode() == 0 )
   funds -= 0.01 * AccountStopoutLevel() * MathMax ( AccountBalance() , AccountEquity() );
   if ( AccountStopoutMode() == 1 ) funds -= AccountStopoutLevel();
   funds -= AccountMargin();
   if ( ! ( funds > 0.0 ) ) return(0);
   double lotd = MarketInfo ( sy , 32 );
   if ( ! ( lotd > 0.0 ) ) return(0);
   double available = funds / lotd,
   minl = MarketInfo ( sy , 23 );
   if ( available < minl ) return(0);
   double maxl = MarketInfo ( sy , 25 ),
   pval = MarketInfo ( sy , 16 ),
   stepl = MarketInfo ( sy , 24 ),
   spr = MarketInfo ( sy , 10 ) - MarketInfo ( sy , 9 ),
   dig = MarketInfo ( sy , 12 ),
   pnt = MarketInfo ( sy , 11 );
   if ( ! ( maxl > 0.0 ) ) maxl = 999999;
   if ( dig < 4 ) pnt = 0.01;
   if ( dig > 3 ) pnt = 0.0001;
   double costrisk = ( spr / pnt + StopLoss ) * available * pval + funds;
   // if ( available / costrisk * funds < minl ) return(0);
   if ( ! ( stepl > 0.0 ) ) stepl = minl;
   double free = funds / lotd / costrisk * funds *0.01* AccountRisk;
   int tmp = free / stepl;
   double lot = MathMin ( maxl ,  MathMax( tmp * stepl , minl )  );
   return ( lot );  }
   
p.s. About the "// SpeechText(str,SPEECH_ENGLISH); ", which additional file or library you've been using for that code? (I'm interested, just asking)
Files:
 

Thanks . I don't for sure how this will work but I downloaded it. All I want is for manual control of the amount of lots being executed in sequence.

The EA just keeps firing them off. After running it on a Demo acct. that at the time there was over $25,000 in it. It created about $5000 in Drawdown

or 25%. This is why I can't let it run in my own acct. without having it control the number of lots.

Oh yeah, the SpeechText code is from part of another EA that I used. I don't know for sure what is behind it other than I think there was maybe more than

one language in the text. It is necessary to make the Alert code in my EA work properly.

JimTrader1

 
Sorry, I reviewed the code and found a mistake in
   int tmp = MathMax( free / stepl , minl );
   double lot = MathMin ( maxl , tmp * stepl );
and I replaced/fixed it in the text with
   int tmp = free / stepl;
   double lot = MathMin ( maxl ,  MathMax( tmp * stepl , minl )  );

-- " All I want is for manual control of the amount of lots being executed in sequence. "

-- " I feel that scaling lot entrys at different prices is somewhat better. "

Explain to me better, if I understood correctly :

1. ex.: Do You want first entry to be minimum allowed lots ?

2. And the next (and the next-next) entry to be with bigger lot size if price moves "in direction" ?

3. or if it moves in "opposite direction" ?

Which of these applies ?

 
rfb:
Sorry, I reviewed the code and found a mistake in
and I replaced/fixed it in the text with

-- " All I want is for manual control of the amount of lots being executed in sequence. "

-- " I feel that scaling lot entrys at different prices is somewhat better. "

Explain to me better, if I understood correctly :

1. ex.: Do You want first entry to be minimum allowed lots ?

2. And the next (and the next-next) entry to be with bigger lot size if price moves "in direction" ?

3. or if it moves in "opposite direction" ?

Which of these applies ?


Ok, Thanks much for your second reply. I really need to get this working correctly.I have been sick for about 11 days.

Doesn't help me. Here is what I am trying to do: Not interested in increasing the Lot size base on Profit etc. or Martingale methods etc.

At least not right now. When you run it in the Demo acct. on 1 or 2 microlots it just keeps pounding out the Trades. 1micro and another and another until

the Signal Criteria is no longer valid etc. If I increase the Lot size to 1 or 2 Mini Lots it will reduce the number of trades.Margin control working I guess?

Because of the small size of my acct., I have to have it trade Micro Lots for now. Can't have it going crazy and keep scaling in more and more. Yeah the

Margin control will probably shut it down at some point. I want to be able to put a cap on the number of trades or INDIVIDUAL lots it executes. I would

interpret this as Overriding the LotsOptimizer. If this can't be done just being able to choose the Maximum number of trades AND lot size is fine. Or NO

LotsOptimizer.

Also after much trouble getting it to work right for me, the Delay code I have put in the EA doesn't seem to be working now. I can tell by putting

the indicators(sto & rsi) on the chart and running the visual tester. These 2 things I really need to get corrected and will make considerable difference.

Because of the time I have been spending on this and now being sick for 11 days, I am willing to pay you if necessary to help me get this darn thing

working right. I am sending the code I have been working with.

Thanks,

JimTrader1

Files:
 
You don't need to post the code..., but when you did it I saw you've done all that you wrote. About margin control you can use your RiskFactor setting or...

if( freeFunds + lotsNewFunds < accBalance * 0.01 * accRiskLimitPercent - marginCallSum ) noError = true
 
rfb:
You don't need to post the code..., but when you did it I saw you've done all that you wrote. About margin control you can use your RiskFactor setting or...

if( freeFunds + lotsNewFunds < accBalance * 0.01 * accRiskLimitPercent - marginCallSum ) noError = true

Looks like we can put some control on the number of trades with just the Margin control.

Should cap the number of trades under a certain amount even though not always the same number correct?