
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 everyone,
This is a stupid coding question, and I know I've seen it somewhere before, but I need help.
I'm coding a custom indicator, and all I want it to do is read the current bid price at ONLY THE BEGINNING of a NEW bar. I can't just use Open[0] because every time a new tick comes in it will keep returning the open value for the current bar. I want the value to be returned only once, until a new bar is formed.
I know I'm missing something quite simple here, but am having a bit of trouble figuring it out. Could someone help me?
Thanks,
-wolfe
Hello everyone,
This is a stupid coding question, and I know I've seen it somewhere before, but I need help.
I'm coding a custom indicator, and all I want it to do is read the current bid price at ONLY THE BEGINNING of a NEW bar. I can't just use Open[0] because every time a new tick comes in it will keep returning the open value for the current bar. I want the value to be returned only once, until a new bar is formed.
I know I'm missing something quite simple here, but am having a bit of trouble figuring it out. Could someone help me?
Thanks,
-wolfeJust store the current bar time (Time[0]) - when this value changes, you have a new bar, so get your price, store new value and repeat...
Just store the current bar time (Time[0]) - when this value changes, you have a new bar, so get your price, store new value and repeat...
Thanks omelette,
I should have thought of that, kinda disappointed in myself!
Thanks for the help!
Can someone else show me what im doing wrong to this code?
I would like to add more timeframe into it like timeframe Daily,but i do not know what wrong
//| #MTF_Hi_Low_Middle.mq4
//| Base from spudfibo.Upgrade by Darkkiller
//: Thanks to Mladen for helping me to make some correction
//+------------------------------------------------------------------+
#property indicator_chart_window
extern string note1 = "H4 Higher,Middle,Lower colors";
extern color H4HigherColor = DeepSkyBlue;
extern color H4MiddleColor = Yellow;
extern color H4LowerColor = HotPink;
extern string note2 = "Draw H4 Higher,Lower and Middle?";
extern bool H4HiLow = true;
extern bool H4Mid = true;
extern string note3 = "D1 Higher,Middle,Lower colors";
extern color D1HigherColor = DeepSkyBlue;
extern color D1MiddleColor = Yellow;
extern color D1LowerColor = HotPink;
extern string note4 = "Draw D1 Higher,Lower and Middle?";
extern bool D1HiLow = true;
extern bool D1Mid = true;
double HiPrice, LoPrice, Range, D1HiPrice, D1LoPrice, D1Range;
datetime StartTime;
int init()
{
return(0);
}
int deinit()
{
ObjectDelete("H4Higher");
ObjectDelete("H4Lower");
ObjectDelete("H4Middle");
ObjectDelete("D1Higher");
ObjectDelete("D1Lower");
ObjectDelete("D1Middle");
return(0);
}
//+------------------------------------------------------------------+
//| Draw Fibo
//+------------------------------------------------------------------+
int DrawFibo()
{
///////////////////////////////////////////HILO/////
if(H4HiLow)
{
if(ObjectFind("H4Higher") == -1)
ObjectCreate("H4Higher", OBJ_FIBO, 0, StartTime, HiPrice+Range, StartTime, HiPrice);
else
{
ObjectSet("H4Higher",OBJPROP_TIME2, StartTime);
ObjectSet("H4Higher",OBJPROP_TIME1, StartTime);
ObjectSet("H4Higher",OBJPROP_PRICE1,HiPrice+Range);
ObjectSet("H4Higher",OBJPROP_PRICE2,HiPrice);
}
ObjectSet("H4Higher", OBJPROP_LEVELCOLOR, H4HigherColor);
ObjectSet("H4Higher", OBJPROP_FIBOLEVELS,1);
ObjectSet("H4Higher", OBJPROP_FIRSTLEVEL+0,0.0); ObjectSetFiboDescription("H4Higher", 0, "H4 HIGHER- %$");
ObjectSet("H4Higher", OBJPROP_RAY,true);
ObjectSet("H4Higher", OBJPROP_BACK,true);
ObjectSet("H4Higher", OBJPROP_COLOR,EMPTY);
if(ObjectFind("H4Lower") == -1)
ObjectCreate("H4Lower", OBJ_FIBO, 0, StartTime, LoPrice-Range, StartTime, LoPrice);
else
{
ObjectSet("H4Lower", OBJPROP_TIME2, StartTime);
ObjectSet("H4Lower", OBJPROP_TIME1, StartTime);
ObjectSet("H4Lower", OBJPROP_PRICE1,LoPrice-Range);
ObjectSet("H4Lower", OBJPROP_PRICE2,LoPrice);
}
ObjectSet("H4Lower", OBJPROP_LEVELCOLOR, H4LowerColor);
ObjectSet("H4Lower", OBJPROP_FIBOLEVELS, 1);
ObjectSet("H4Lower", OBJPROP_FIRSTLEVEL+0,0.0); ObjectSetFiboDescription("H4Lower", 0, "H4 LOWER - %$");
ObjectSet("H4Lower", OBJPROP_RAY, true);
ObjectSet("H4Lower", OBJPROP_BACK, true);
ObjectSet("H4Lower", OBJPROP_COLOR, EMPTY);
}
if(D1HiLow)
{
if(ObjectFind("D1Higher") == -1)
ObjectCreate("D1Higher", OBJ_FIBO, 0, D1StartTime, D1HiPrice+D1Range, D1StartTime, D1HiPrice);
else
{
ObjectSet("D1Higher", OBJPROP_TIME2, D1StartTime);
ObjectSet("D1Higher", OBJPROP_TIME1, D1StartTime);
ObjectSet("D1Higher", OBJPROP_PRICE1, D1HiPrice+D1Range);
ObjectSet("D1Higher", OBJPROP_PRICE2, D1HiPrice);
}
ObjectSet("D1Higher", OBJPROP_LEVELCOLOR, D1HigherColor);
ObjectSet("D1Higher", OBJPROP_FIBOLEVELS,1);
ObjectSet("D1Higher", OBJPROP_FIRSTLEVEL+0,0.0); ObjectSetFiboDescription("D1Higher", 0, "H4 HIGHER- %$");
ObjectSet("D1Higher", OBJPROP_RAY, true);
ObjectSet("D1Higher", OBJPROP_BACK, true);
ObjectSet("D1Higher", OBJPROP_COLOR, EMPTY);
if(ObjectFind("D1Lower") == -1)
ObjectCreate("D1Lower", OBJ_FIBO, 0, D1StartTime, D1LoPrice-D1Range, D1StartTime, 1LoPrice);
else
{
ObjectSet("D1Lower", OBJPROP_TIME2, D1StartTime);
ObjectSet("D1Lower", OBJPROP_TIME1, D1StartTime);
ObjectSet("D1Lower", OBJPROP_PRICE1, D1LoPrice-D1Range);
ObjectSet("D1Lower", OBJPROP_PRICE2, D1LoPrice);
}
ObjectSet("D1Lower", OBJPROP_LEVELCOLOR, D1LowerColor);
ObjectSet("D1Lower", OBJPROP_FIBOLEVELS,1);
ObjectSet("D1Lower", OBJPROP_FIRSTLEVEL+0,0.0); ObjectSetFiboDescription("D1Lower", 0, "H4 LOWER - %$");
ObjectSet("D1Lower", OBJPROP_RAY, true);
ObjectSet("D1Lower", OBJPROP_BACK, true);
ObjectSet("D1Lower", OBJPROP_COLOR, EMPTY);
}
/////////////////////////////////////////HILO////////
/////////////////////////////////////////MIDDLE////
if(H4Mid)
if(ObjectFind("H4Middle") == -1)
ObjectCreate("H4Middle", OBJ_FIBO, 0, StartTime, HiPrice, StartTime+PERIOD_H4*60, LoPrice);
else
{
ObjectSet("H4Middle", OBJPROP_TIME2, StartTime);
ObjectSet("H4Middle", OBJPROP_TIME1, StartTime+PERIOD_H4*60);
ObjectSet("H4Middle", OBJPROP_PRICE1, HiPrice);
ObjectSet("H4Middle", OBJPROP_PRICE2, LoPrice);
}
ObjectSet("H4Middle", OBJPROP_LEVELCOLOR, H4MiddleColor);
ObjectSet("H4Middle", OBJPROP_FIBOLEVELS,1);
ObjectSet("H4Middle", OBJPROP_FIRSTLEVEL+0,0.500); ObjectSetFiboDescription("H4Middle", 0, "H4 MIDDLE - %$");
ObjectSet("H4Middle", OBJPROP_RAY, true);
ObjectSet("H4Middle", OBJPROP_BACK, true);
ObjectSet("H4Middle", OBJPROP_COLOR, EMPTY);
}
if(D1Mid)
if(ObjectFind("D1Middle") == -1)
ObjectCreate("D1Middle", OBJ_FIBO, 0, D1StartTime, D1HiPrice, D1StartTime+PERIOD_D1*60, D1LoPrice);
else
{
ObjectSet("D1Middle", OBJPROP_TIME2, D1StartTime);
ObjectSet("D1Middle", OBJPROP_TIME1, D1StartTime+PERIOD_D1*60);
ObjectSet("D1Middle", OBJPROP_PRICE1, D1HiPrice);
ObjectSet("D1Middle", OBJPROP_PRICE2, D1LoPrice);
}
ObjectSet("D1Middle", OBJPROP_LEVELCOLOR, D1MiddleColor);
ObjectSet("D1Middle", OBJPROP_FIBOLEVELS,1);
ObjectSet("D1Middle", OBJPROP_FIRSTLEVEL+0,0.500); ObjectSetFiboDescription("D1Middle", 0, "D1 MIDDLE - %$");
ObjectSet("D1Middle", OBJPROP_RAY, true);
ObjectSet("D1Middle", OBJPROP_BACK, true);
ObjectSet("D1Middle", OBJPROP_COLOR, EMPTY);
}
/////////////////////////////////////////MIDDLE////
//+-----------------------------------------------+
//| Indicator start function
//+-----------------------------------------------+
int start()
{
int shift = iBarShift(NULL, PERIOD_D1, Time[0]) + 1; // H4
HiPrice = iHigh(NULL, PERIOD_H4, shift);
LoPrice = iLow (NULL, PERIOD_H4, shift);
StartTime = iTime(NULL, PERIOD_H4, shift);
D1HiPrice = iHigh(NULL, PERIOD_D1, shift);
D1LoPrice = iLow (NULL, PERIOD_D1, shift);
D1StartTime = iTime(NULL, PERIOD_D1, shift);
if(TimeDayOfWeek(StartTime) == 0/*Sunday*/)
{//Add fridays high and low
HiPrice = MathMax(HiPrice, iHigh(NULL,PERIOD_H4, shift+1));
LoPrice = MathMin(LoPrice, iLow(NULL,PERIOD_H4, shift+1));
D1HiPrice = MathMax(D1HiPrice, iHigh(NULL, PERIOD_D1, shift+1));
D1LoPrice = MathMin(D1LoPrice, iLow(NULL, PERIOD_D1, shift+1));
}
Range = HiPrice - LoPrice;
D1Range = D1HiPrice - D1LoPrice;
DrawFibo();
return(0);
}
//+------------------------------+
Bellow this i attach the original for H4 high low mid
I would like some help please I am trying to use the delta-stop as a stop loss
and trailing stop. Attached is the EA.
Is it posible to do this.
//+------------------------------------------------------------------+
//| MODIFIED BY Avery T. Horton, Jr. aka TheRumpledOne |
//| |
//| |
//|
//
// google search "therumpledone mt4"
//
//+------------------------------------------------------------------+
//| _Fibo_Hi_Low_Middle.mq4
//| Base from spudfibo.Upgrade by Darkkiller
//: Thanks to Mladen for helping me to make some correction
//+------------------------------------------------------------------+
#property indicator_chart_window
extern int myChartPeriod = 0 ;
extern string note1 = "Higher,Middle,Lower colors";
extern color HigherColor = DeepSkyBlue;
extern color MiddleColor = Yellow;
extern color LowerColor = HotPink;
extern string note2 = "Draw middle?";
extern bool HiLow = true;
extern bool Mid = true;
double HiPrice, LoPrice, Range;
datetime StartTime;
string tChartPeriod, tHigher, tLower, tMiddle ;
int init()
{
if(myChartPeriod == 0) { myChartPeriod = Period() ; }
tChartPeriod = TimeFrameToString(myChartPeriod) ;
tHigher = tChartPeriod + "H" ;
tLower = tChartPeriod + "L" ;
tMiddle = tChartPeriod + "M" ;
return(0);
}
int deinit()
{
ObjectDelete(tHigher);
ObjectDelete(tLower);
ObjectDelete(tMiddle);
return(0);
}
//+------------------------------------------------------------------+
//| Draw Fibo
//+------------------------------------------------------------------+
int DrawFibo()
{
if(HiLow)
{
if(ObjectFind(tHigher) == -1)
ObjectCreate(tHigher,OBJ_FIBO,0,StartTime,HiPrice+Range,StartTime,HiPrice);
else
{
ObjectSet(tHigher,OBJPROP_TIME2, StartTime);
ObjectSet(tHigher,OBJPROP_TIME1, StartTime);
ObjectSet(tHigher,OBJPROP_PRICE1,HiPrice+Range);
ObjectSet(tHigher,OBJPROP_PRICE2,HiPrice);
}
ObjectSet(tHigher,OBJPROP_LEVELCOLOR,HigherColor);
ObjectSet(tHigher,OBJPROP_FIBOLEVELS,1);
ObjectSet(tHigher,OBJPROP_FIRSTLEVEL+0,0.0);
ObjectSetFiboDescription(tHigher,0,tChartPeriod+" HIGHER- %$");
ObjectSet(tHigher,OBJPROP_RAY,true);
ObjectSet(tHigher,OBJPROP_BACK,true);
ObjectSet(tHigher,OBJPROP_COLOR,EMPTY);
if(ObjectFind(tLower) == -1)
ObjectCreate(tLower,OBJ_FIBO,0,StartTime,LoPrice-Range,StartTime,LoPrice);
else
{
ObjectSet(tLower,OBJPROP_TIME2, StartTime);
ObjectSet(tLower,OBJPROP_TIME1, StartTime);
ObjectSet(tLower,OBJPROP_PRICE1,LoPrice-Range);
ObjectSet(tLower,OBJPROP_PRICE2,LoPrice);
}
ObjectSet(tLower,OBJPROP_LEVELCOLOR,LowerColor);
ObjectSet(tLower,OBJPROP_FIBOLEVELS,1);
ObjectSet(tLower,OBJPROP_FIRSTLEVEL+0,0.0);
ObjectSetFiboDescription(tLower,0,tChartPeriod+" LOWER - %$");
ObjectSet(tLower,OBJPROP_RAY,true);
ObjectSet(tLower,OBJPROP_BACK,true);
ObjectSet(tLower,OBJPROP_COLOR,EMPTY);
}
/////////////////////////////////////////MIDDLE///////////////////////////
if(Mid)
if(ObjectFind(tMiddle) == -1)
ObjectCreate(tMiddle,OBJ_FIBO,0,StartTime,HiPrice,StartTime+myChartPeriod*60,LoPrice);
else
{
ObjectSet(tMiddle,OBJPROP_TIME2, StartTime);
ObjectSet(tMiddle,OBJPROP_TIME1, StartTime+myChartPeriod*60);
ObjectSet(tMiddle,OBJPROP_PRICE1,HiPrice);
ObjectSet(tMiddle,OBJPROP_PRICE2,LoPrice);
}
ObjectSet(tMiddle,OBJPROP_LEVELCOLOR,MiddleColor);
ObjectSet(tMiddle,OBJPROP_FIBOLEVELS,1);
ObjectSet(tMiddle,OBJPROP_FIRSTLEVEL+0,0.500);
ObjectSetFiboDescription(tMiddle,0,tChartPeriod+" MIDDLE - %$");
ObjectSet(tMiddle,OBJPROP_RAY,true);
ObjectSet(tMiddle,OBJPROP_BACK,true);
ObjectSet(tMiddle,OBJPROP_COLOR,EMPTY);
}
//+------------------------------------------------------------------+
//| Indicator start function
//+------------------------------------------------------------------+
int start()
{
int shift = iBarShift(NULL,myChartPeriod,Time[0]) + 1; //
HiPrice = iHigh(NULL,myChartPeriod,shift);
LoPrice = iLow (NULL,myChartPeriod,shift);
StartTime = iTime(NULL,myChartPeriod,shift);
if(TimeDayOfWeek(StartTime)==0/*Sunday*/)
{//Add fridays high and low
HiPrice = MathMax(HiPrice,iHigh(NULL,myChartPeriod,shift+1));
LoPrice = MathMin(LoPrice,iLow(NULL,myChartPeriod,shift+1));
}
Range = HiPrice-LoPrice;
DrawFibo();
// Comment( "Period_", tChartPeriod ) ;
return(0);
}
//+------------------------------------------------------------------+
string TimeFrameToString(int tf)
{
string tfs;
switch(tf) {
case PERIOD_M1: tfs="M1" ; break;
case PERIOD_M5: tfs="M5" ; break;
case PERIOD_M15: tfs="M15" ; break;
case PERIOD_M30: tfs="M30" ; break;
case PERIOD_H1: tfs="H1" ; break;
case PERIOD_H4: tfs="H4" ; break;
case PERIOD_D1: tfs="D1" ; break;
case PERIOD_W1: tfs="W1" ; break;
case PERIOD_MN1: tfs="MN";
}
return(tfs);
}
That's how I did it.
P.S. why are my attachments getting deleted?
MoveStopOnce
Hello, trying to get this MoveStopOnce code to work but the Sell trades don't seem to get modified by the code, just the Buys. Anything wrong?
//Buys
//MoveOnce
if(MoveStopOnce && MoveStopWhenPrice > 0) {
if(Bid - OrderOpenPrice() >= Point * MoveStopWhenPrice) {
if(OrderStopLoss() < OrderOpenPrice() + Point * MoveStopTo) {
OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() + Point * MoveStopTo, OrderTakeProfit(), 0, Red);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
[/code]
[code]
//Sells
//MoveOnce
if(MoveStopOnce && MoveStopWhenPrice > 0) {
if(OrderOpenPrice() - Ask >= Point * MoveStopWhenPrice) {
if(OrderStopLoss() > OrderOpenPrice() - Point * MoveStopTo) {
OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() - Point * MoveStopTo, OrderTakeProfit(), 0, Red);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
MoveStopOnce
I have had this problem.
I think you need to add:
if (OrderType() == OP_BUY)
AND use OP_SELL for the sell code.
Big Be
I have had this problem.
I think you need to add:
if (OrderType() == OP_BUY)
AND use OP_SELL for the sell code.
Big BeOk, I'll try it when I get home but then why does it still work with Buy orders already?
Thanks