shift=-6 i think will cause the problem. i assume it will only be valid for bars_index>6
//z
if(Volume[0]>1) return;
Volume is unreliable.static datetime Time0; bool newBar = Time0 < Time[0]; if (!newBar) return(0); Time0 = Time[0];
OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,Ask-SL*Point
EA's should adjust for 5 digit brokers, TP, SL, and slippage//++++ These are adjusted for 5 digit brokers. double pips2points, // slippage 3 pips 3=points 30=points pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
zzuegg:
Right on zzuegg. I can't believe I overlooked the fact that I was trying to read something which does not exist yet (it is 6 bars behind), hence the zero value... of course. Thanks
shift=-6 i think will cause the problem. i assume it will only be valid for bars_index>6
//z
WHRoeder:
-
Volume is unreliable.
-
EA's should adjust for 5 digit brokers, TP, SL, and slippage
Thanks for the pointers. What would you use instead of volume to force an action at the very opening time of the new bar? (Minute() == 0)?
Time[] or iTime()
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,
Trying to so a simple task really. Took a prepackaged MA sample (I believe I downloaded it from the code base here), and added another faster MA (10 SMA) to the code and I am trying to read both iMA values at the signal time to confirm divergence/conv. For some freakin' reason, the second MA is always returning a value of zero. I added a third one, the same result. I switched the line around to different places and even placed in the main program, still comes back as zero. The code is straight from the MA Sample, with the exception of my secondma (and some TP and SL mods which are not related to the problem at hand). Again, ma is returning valid values at every tick, but secondma is always zero! The movingperiod and shift for the second ma is 10 and -6. The indicator gets drawn properly on the tester chart after a run, with the proper format. Any help would be greatly appreciated. TIA
void CheckForOpen()
{
double ma,secondma;
int res;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//---- get Moving Average (added secondma for comparison)
ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
secondma=iMA(NULL,0,SecondMovingPeriod,SecondMovingShift,MODE_SMA,PRICE_CLOSE,0);
//---- sell conditions
if(Open[1]>ma && Close[1]<ma && ma > secondma)
{
Print("SELL condition...MA is: ",ma, " Second ma is: ",secondma);
/****** Bid+SL*Point Bid-TP*Point */
res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,Bid+SL*Point,0,"",MAGICMA,0,Red);
return;
}
//---- buy conditions
if(Open[1]< ma && Close[1]> ma && secondma > ma)
{
Print("BUY condition...MA is: ",ma, " Second ma is: ",secondma);
/*************Ask-SL*Point Ask+TP*Point */
res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,Ask-SL*Point,0,"",MAGICMA,0,Blue);
return;
}
//----
}