Ask! - page 64

 
ryanklefas:
I think the normalizeDouble function would work for you too. I've also seen code that uses the MathFloor and MathCeiling functions to accomplish the same thing.

So, what your saying is that the calculation should work the way I have it coded in the "Variable Begin" section as indicated below:

double LotSize = NormalizeDouble(Lot_Size_Ratio*((AccountBalance()/1000)), 3);

Then maybe my problem is elsewhere, because when I set the following:

extern bool LotSizeManager = True;

the EA does not execute any trades. When I set it to false it will execute trades. I'm assuming it is not executing any trades when this value is True because there is a problem with the calculation.

 
waaustin:
double LotSize = NormalizeDouble(Lot_Size_Ratio*((AccountBalance()/1000)), 3);

double LotSize = NormalizeDouble(Lot_Size_Ratio*((AccountBalance()/1000)), 1); // 0: fulllots, 1: minilots, 2: microlots, 3: never used

 
Michel:
double LotSize = NormalizeDouble(Lot_Size_Ratio*((AccountBalance()/1000)), 1); // 0: fulllots, 1: minilots, 2: microlots, 3: never used

So your saying is it depends what accuracy I want the lotsize to be. So if I want microlot accuracy, such as 0.75 Lots, then I would use a value of 2.

 
waaustin:
So your saying is it depends what accuracy I want the lotsize to be. So if I want microlot accuracy, such as 0.75 Lots, then I would use a value of 2.

Yes, you got it !

But be sure that microlots (2 decimals) are ok for your broker and the type of account you have.

I do not know very well how IBFX works with mini account, ie if microlots on miniaccounts are also named minilots and have only 1 decimal. Maybe some one using IBFX may answer here ?

Nevertheless, the best is to ask your broker.

 
Michel:
Yes, you got it !

But be sure that microlots (2 decimals) are ok for your broker and the type of account you have.

I do not know very well how IBFX works with mini account, ie if microlots on miniaccounts are also named minilots and have only 1 decimal. Maybe some one using IBFX may answer here ?

Nevertheless, the best is to ask your broker.

Thanks alot. The LotSizing code seems to work fine. However, it appears I have another bug in the code somewhere and I can't figure it out.

I have the EA loaded on more than one pair, it will place trades only on one pair. The LotSizing code works fine. But, it doesn't place any more trades on any other currency pairs. However, when I set the following value:

extern bool LotSizeManager = False;

the EA places trades for every currency pair I have the EA attached to.

 
waaustin:
Thanks alot. The LotSizing code seems to work fine. However, it appears I have another bug in the code somewhere and I can't figure it out.

I have the EA loaded on more than one pair, it will place trades only on one pair. The LotSizing code works fine. But, it doesn't place any more trades on any other currency pairs. However, when I set the following value:

extern bool LotSizeManager = False;

the EA places trades for every currency pair I have the EA attached to.

Never Mind. I figured out where the problem is! Thanks for the help.

 

Problem: At the user defined time, the EA tries to place a pending order but the current price is to close for the broker to accept the order.

Question: How would I code a loop that would check the iOpen of the 1 minute bar every minute until it accepts the order? Just not sure how to incorperated the check every minute until the order can be entered. Seems like the current code forgets what it is looking for after a few minutes because once the price is out of the way of entry nothing happens.

I think part of it is as follows:

double Open_Price_Every_Minute;

Open_Price_Every_Minute = iOpen(NULL,PERIOD_M1,0);

Open_Price_Every_Minute = NormalizeDouble(Open_Price_Every_Minute, Digits);

if (Allow_LimitOrder_for_Entry_A==false)

{

OrderSend(Symbol(), OP_BUYSTOP, Lots, LA, Slippage, LASL, LATP, "", Magic, 0, FireBrick);

OrderSend(Symbol(), OP_SELLSTOP, Lots, SA, Slippage, SASL, SATP, "", Magic, 0, FireBrick);

}

As always, Thanks for your assistance and time.

James

 
proverbs:
Seems like the current code forgets what it is looking for after a few minutes because once the price is out of the way of entry nothing happens.

I don't think you're going to want to have loop running indefinitely in an EA. I've never tried it before, but I don't think it would be a good thing. If you want the EA to "remember" what it has been doing, store whatever data you need to remember as static variables (varaibles declared outside of the main function) or as MT4 global variables.

 
ryanklefas:
I don't think you're going to want to have loop running indefinitely in an EA. I've never tried it before, but I don't think it would be a good thing. If you want the EA to "remember" what it has been doing, store whatever data you need to remember as static variables (varaibles declared outside of the main function) or as MT4 global variables.

Hey!

Puting ea procesing in the loop is a good way, read this:

https://www.mql5.com/en/articles/1462

You just need to do it in the right way

 

Kalenzo,

Thanks for the article. Looks like I am about to learn more than I asked for.