Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1063
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello Guru.
Can you tell me if I'm on the right track?
Objective: to introduce a variable lot size depending on the distance from the MA.
In the input parameters:
extern double Lot1 = 0.01; // first variant of lot
extern double Lot2 = 0.03; // second variant of lot
extern int Distan = 20; // distance from SlowMA
Ma has been defined in the Expert Advisor body:
double SlowMA = iMA(NULL,60,periodSlowMA,0,MODE_EMA,PRICE_MEDIAN,0);
Further we need a condition: if the current price (Bid or Ask depending on direction) is up to the Distant size, we use the first lot size, if it is more, we use the second one.
The first thing that came to mind:
if (Ask-SlowMA<Distan) Lot == Lot1;
if (SlowMA-Bid<Distan) Lot == Lot1;
if (Ask-SlowMA>Distan) Lot == Lot2;
if (SlowMA-Bid>Distan) Lot == Lot2;
But it doesn't work. The error is either in Lot connections or in general logic.
Thanks in advance.
Hello Guru.
Can you tell me if I'm on the right track?
Objective: to introduce a variable lot size depending on the distance from the MA.
In the input parameters:
extern double Lot1 = 0.01; // first lot size
extern double Lot2 = 0.03; // second lot variant.
extern int Distan = 20; // distance from the SlowMA
In the body of the Expert Advisor defined Ma:
double SlowMA = iMA(NULL,60,periodSlowMA,0,MODE_EMA,PRICE_MEDIAN,0);
Then we need a condition: if the current price (Bid or Ask depending on direction) is up to the Distant size, we use the first lot size, if it is larger, we use the second.
The first thing that came to mind:
if (Ask-SlowMA<Distan) Lot == Lot1;
if (SlowMA-Bid<Distan) Lot == Lot1;
if (Ask-SlowMA>Distan) Lot == Lot2;
if (SlowMA-Bid>Distan) Lot == Lot2;
But it doesn't work. It's either an error in conjunction with Lot, or in general logic.
Thank you in advance.
Bid and Ask are the last known bid and ask prices, i.e. the current price.
SlowMA is my renamed Ma
(double SlowMA = iMA(NULL,60,periodSlowMA,0,MODE_EMA,PRICE_MEDIAN,0);)
The deviation of the current price (Bid or Ask) from the Ma (SlowMA) can be more or less than Distans. According to this you should set either the first or the second lot size.
I've found variants of changing the lot based on the deposit or the number of open orders, but I can't get any response from such a linear term.
Something tells me we need a function that returns an absolute value. I.e. if we apply it to a negative number, the result will be positive.
Bid and Ask are the last known bid and ask prices, i.e. the current price.
SlowMA is my renamed Ma
(double SlowMA = iMA(NULL,60,periodSlowMA,0,MODE_EMA,PRICE_MEDIAN,0);)
The deviation of the current price (Bid or Ask) from the Ma (SlowMA) can be more or less than Distans. According to this you should set either the first or the second lot size.
I've found variants of changing the lot based on the deposit or the number of open orders, but I can't get any response from such a linear term.
Something tells me we need a function that returns an absolute value. I.e. if we apply it to a negative number, the result will be positive.
The absolute value of the difference of Bid and MA may be needed a bit later; now, since you haven't got the hint, let's calculate together
Bid = 1.12730;
MA = 1.12530;
Distans = 20;
Question:
When and whether 1.1273 to 1.1253 will be more than 20???
For some reason my calculator shows 0.002 only. But that's a long way from 20...
Thank you, I see. Or you could do it like this:
dist=Distan*Point;
if (Ask-SlowMA<dist) Lot == Lot1;
if (SlowMA-Bid<dist) Lot == Lot1;
if (Ask-SlowMA>dist) Lot == Lot2;
if (SlowMA-Bid>dist) Lot == Lot2;
So how do I do this properly?
Thank you, I see. Or you could do it like this:
dist=Distan*Point;
if (Ask-SlowMA<dist) Lot == Lot1;
if (SlowMA-Bid<dist) Lot == Lot1;
if (Ask-SlowMA>dist) Lot == Lot2;
if (SlowMA-Bid>dist) Lot == Lot2;
So how do I do this properly?
And now we can use MathAbs() in order not to overthink our head by keeping track of what is being subtracted from what. And there is another interesting conditional operator
Lot = MathAbs(Ask-SlowMA) < dist ? Lot1 : Lot2;
Which means: The Lot variable will be assigned the value of Lot1 if Ask- SlowMA is less than dist, otherwise, the value of Lot2 will be assigned.
One more recommendation: Forget the Point variable. Use _Point or the Point() function
I need help, I am still just learning...
And now you can apply MathAbs() so that you don't have to keep track of what to subtract from what. And another interesting conditional operator
Which means: The Lot variable will be assigned the value of Lot1 in case Ask- SlowMA is less than dist, otherwise, the value of Lot2 will be assigned.
One more recommendation: Forget the Point variable. Use _Point or the Point() function
What about Point, does it seem to be working?
The Volga GAZ 21 also works. And even the president drives one, but for some reason no one buys it for use. They only buy it as an antique.