Coding Forex: Forcing Code to Run Only Once Per Candle

Поділитися
Вставка
  • Опубліковано 12 вер 2024
  • Mql4 Progamming Tutorials and Forex Trading Training. learnmql4.com
    Jimdandy Trade Management Tool..
    www.mql5.com/e...
    Skill Builder. www.mql5.com/e...
    My kindle book :
    www.amazon.com...
    Patreon / jimdandy1958
    Ever written an indicator or EA that is supposed to notify you when something happens? Then, after it DOES happen, it won't stop telling you about it? On every tick that comes in it keeps telling you the same thing over and over..
    This video addresses that problem. How do you get your code to alert you and then KNOW that it's already told you so it will stop alerting.
    I will show you what NOT to do and then I will show you how to use static variables properly. There is something peculiar about using them that differs from other normal global variables.
    Like, Share and Subscribe PipPip #mql4...
    REMEMBER TO CLICK THE NOTIFICATION BELL AFTER YOU SUBSCRIBE.
    If you'd like to support my channel, check out the affiliate links below to the two things I get asked about most... my hat and my mic...
    My Mic a Shure 55SH Series II.. amzn.to/2xznsft
    My Authentic Greek Fisherman's Cap.. amzn.to/2y5FGpd
    This is links to the equipment I use in this video.
    My WebCam...
    Logitech HD Pro Webcam C920. amzn.to/2xoA3DH
    My Green Screen and Lights..
    Green Screen with Lights. amzn.to/2y220OP
    My Audio Mixer.
    Behringer Xenyx 502 Audio Mixer. amzn.to/2z5Zc3o
    Cable to hook mixer to computer.
    BreakOut Cable Dual 1/4 inch to 3.5m trs amzn.to/2xqsLdZ

КОМЕНТАРІ • 74

  • @balberith1533
    @balberith1533 7 місяців тому

    I'm learning about mql4 coding since 2 months ago.
    Was looking for something to limit my orders placing once per bar and it's the first content I found teaching something what really works.
    I coded about 30 different bots already and some of them weren't working because of the lack of this and I finally found a video posted 6 years ago teaching about it.
    Thanks a lot.

  • @daveng7839
    @daveng7839 7 років тому +1

    Another great video Jim, thanks so much...
    For my own preference I usually do this:
    static datetime saved_candle_time=Time[0];
    Just so that it will do nothing on the current candle at the first instance when the EA was loaded.

  • @stockmarkettamil9431
    @stockmarkettamil9431 3 роки тому

    your my best grandpa
    thanks a lot

  • @infosysmysore5433
    @infosysmysore5433 2 роки тому

    with the code below:
    Something like a = typeof("string"); to link it to below:
    People wonder what can MA(H,1) or EMA i mean moving averages or exponential moving averages are good for but the client is convinced. I sent him email to consider the macd() line judiciously.
    But lets hope i ask him to do the right thing.

  • @mattglinsmann2233
    @mattglinsmann2233 2 роки тому

    such a wealth of knowledge!!!

  • @danielcioca1
    @danielcioca1 2 роки тому

    Yes but like this ea/indicator starts in the middle of the bar it will think that is the new bar… which is wrong… I think is letter with newbar() function and call it in the Init() first

  • @waynefilkins8394
    @waynefilkins8394 5 років тому +1

    So if you want your entire strategy to run on new candle INSTEAD of on new tick, you can just put those 3 lines of code at the beginning of the onTick function right?

  • @trandungediot
    @trandungediot 5 років тому

    Thankyou! Your code help me solve my problem
    I am from Vietnam, hope that we will exchange and exchange more issues related to MQL code.

  • @timollytips
    @timollytips 7 років тому

    I really enjoy this new video, Thanks Jim, God bless you.

  • @timeless8135
    @timeless8135 4 роки тому

    Very handy Mr.Dandy Thanks

  • @Macam2macam
    @Macam2macam 3 роки тому

    this is simple and effective method. thanks, sir.

  • @MuhammadKhalid-jv4qr
    @MuhammadKhalid-jv4qr 3 роки тому

    Hi Jim,
    This can be achieved by simply placing this line before the code:
    if(Volume[0]==1)
    {
    // write code here
    }
    Please correct me if I miss something!

    • @whathuh6965
      @whathuh6965 2 роки тому

      How can you state it works by adding your code, then contradict yourself by saying correct you if you're missing something?

  • @Dawkins1968
    @Dawkins1968 3 роки тому

    Why not use the bars function instead?

  • @thomasr.miller5553
    @thomasr.miller5553 7 років тому +1

    Great Video.. Can you wright a program that knows what color a candle is with a meter that counts seconds to close ... price value ? Tiny numbers in the margin are hard to see.. Thanks

  • @hamidsh4789
    @hamidsh4789 3 роки тому

    Thanks Jim...Excellent

  •  3 роки тому

    Thank you Jim, you're the one!

  • @prembkurupin
    @prembkurupin 4 роки тому

    Hello Jim, thank for your video it is very helpful.

  • @ndivhuwo137
    @ndivhuwo137 3 роки тому

    Thank you very much, This was really helpful 🙏🏼

  • @jungianshadow4950
    @jungianshadow4950 5 років тому

    Would it be possible to have an indicator like the PSAR to pop up (under/above price) with a certain color popping up and indicating the trade rather than have a notification or automatic trade put in?

  • @AlvaroMenezes
    @AlvaroMenezes 4 роки тому

    Thanks for the content.

  • @MUHAMMADATHER1991
    @MUHAMMADATHER1991 3 роки тому

    Dear Sir, i am trying hard to make the formula of the Average Candlestick Size of nth number of Candle. Can you please teach us about that.

  • @muraterkan3094
    @muraterkan3094 7 років тому +1

    Thank you,
    another helpfull video .

  • @_Kavika
    @_Kavika 7 років тому

    Hello Jim, Thanks for all the videos. I'm learning more and more about coding. Hopefully one day I could build my own EA from scratch. I would like to ask you is it possible to code the EA to give signals; Let's say the MACD open positions only after it crosses the zero line on the second time. For example, when the MACD crosses above the zero line for the first time, as it cross below and then crosses back up (I guess that's 3 crosses), only then will EA initiate a buy position. Can we do that? Also, one more question - I'd love to learn more - Can we use two indicators on an EA to perform what we'd like to do? For instance; When the MACD is below zero and Stochastics is oversold to initiate open positions? Thanks in advance. Looking forward to learn more from you Jimdandy! I love your style of teaching.

    • @AlexTechie
      @AlexTechie 7 років тому +1

      David Lotomau not Jim, but what you're asking is possible. As for the second question, use CustomIndicator() to call the other other indicators from within the EA.

    • @_Kavika
      @_Kavika 7 років тому

      Thanks Alex. I'll start with the script :)

  • @ryancy
    @ryancy 7 років тому

    An easier new candle function that relies on the number of bars on the chart.
    bool IsNewCandle()
    {
    static int BarsOnChart = 0;
    bool theResult = false;
    int aBars = iBars(_Symbol, _Period);
    if (aBars != BarsOnChart)
    {
    BarsOnChart = aBars;
    theResult = true;
    } // end if
    return(theResult);
    } // end IsNewCandle()

    • @Jimdandy1958
      @Jimdandy1958  7 років тому +2

      Richard Yancy
      i stopped using bars on chart long ago. there are other things that can change the number of bars other than a new candle.

  • @ausdeals9
    @ausdeals9 3 роки тому

    Great explanation.. Could you please tell, can this be applied to MQL5 as well? What are the changes in code required for "IsNewCandle" codes?

  • @farzinsb
    @farzinsb 7 років тому

    great point like always. thanks.

  • @juandavidramirez2791
    @juandavidramirez2791 4 роки тому

    HI, i have a problem with my code when i use this function:
    i have 2 array variables declared in a function before i call the isnewcandle(), and before calling the function they have a value, but after calling the function the value for those variables is 0, i have tryed to declare the variables as extern, but apparently an array can’t be declared as extern variable.
    i would be very thankful if you help me with this problem.
    thanks a lot!

  • @sridharm6865
    @sridharm6865 3 роки тому

    thank you sir.

  • @tamurtaj2722
    @tamurtaj2722 3 роки тому

    Hi sir. thanks for posting valuable content here. I have implemented this constraint in my EA's but I don't know what the issue is my EA works great on demos but when I try to run or test in strategy tester the EA won't take more than one trade in the whole time period either its a month or a year. Please guide me through this. Much appreciated.

  • @_Kavika
    @_Kavika 3 роки тому

    Hello Jim, i'm looking for a simple indicator that shows the same open and high price level, in other words, shaven head candlestick, and also for the shaven bottom candlestick... which is of course the same open and low price level. I'll pay you for it. Looking forward to your response, thank you.

    • @Jimdandy1958
      @Jimdandy1958  3 роки тому +1

      I'm sure someone in the freelance area can help you with that for very little money.
      www.mql5.com/en/job

  • @dovhaniramuthaga6506
    @dovhaniramuthaga6506 2 роки тому

    how do i contact you

  • @abbasibrahiam7076
    @abbasibrahiam7076 2 роки тому

    Does this run on the open, high, low or close of the candle? How do we specify when in the candle to run the code should run?

    • @abbasibrahiam7076
      @abbasibrahiam7076 2 роки тому

      Dumb question, you can execute on the open of the next candle = close of current candle haha

  • @timeless8135
    @timeless8135 4 роки тому

    I have a puzzle for someone.
    Does anyone know if its possible to use a while loop that uses an RSI value , which needs to be satisfied to exit the loop ?
    I am not able to get it to work ( will not update the rsi from inside my loop , always sends back the same value) and I have never used a while loop in my code before , but it would be great for a final entry condition after all my other if statements have been passed because I will help to get in on a price reversal in a mean reverting strategy I have .
    code is something like this :
    double rsi = iRSI(plus arguments here) // now rsi is defined in a variable and I will also define it globally too
    if( rsi < 30)
    {
    while( rsi < 30)
    {
    sleep(10000); // slow down the loop
    rsi = rsi ? // try to update the rsi value , not sure if this is required though since rsi is a global variable ??
    Alert("current rsi from inside loop is: " + rsi ); // get an updated rsi to make sure it is updating from inside the loop
    }
    }
    Alert( while loop exited , rsi conditon met" )// then code continues to take a position after this.
    Well, that's all , if any can help I would be eternally grateful :)

  • @petermarius1930
    @petermarius1930 3 роки тому

    Hi Jim I need you to code me an EA how do I contact you personally ?

    • @Jimdandy1958
      @Jimdandy1958  3 роки тому

      If you need coding done then go to the freelance portion of mql5.com

  • @aerialsmx
    @aerialsmx 3 роки тому

    Jimdandy1958, good job, how do I alert one to be given only at the close of the candle?

    • @Jimdandy1958
      @Jimdandy1958  3 роки тому +1

      It's the same thing. When its a new candle that means that a candle just closed. When candle zero closes it reopens a new candle zero and the old candle zero becomes the new candle 1.

  • @mohammedthuabiti9042
    @mohammedthuabiti9042 6 років тому

    Hello Jim, thank for your video it is very helpful. BUT i have two questions for using OnTimer() function.
    How we can use it for One hour for example? Do we need to change EventSetTimer(); to 60?
    Also How we can use it with MultiTimeFrame?
    Thanks in advance.

    • @Jimdandy1958
      @Jimdandy1958  6 років тому +1

      EventSetTime() should be set to the number of seconds you want it to wait between running the OnTimer()
      function. So if you set it to 3600 it will only go off every hour.

    • @touchbands4025
      @touchbands4025 2 роки тому

      @@Jimdandy1958 do you have a video on coding push notifications mobile alerts

  • @gcrack067
    @gcrack067 5 років тому

    hello sir I have a problem of alert ,I get a lot of alert , when a candle open and touching ema is showing a message of alert more times, please can help to fix it, I need once alert per candle open and touching ema

    • @gcrack067
      @gcrack067 5 років тому

      I'm new in code thank you

    • @Jimdandy1958
      @Jimdandy1958  5 років тому

      Once you call the alert, save the candle time. Do not sound alert unless candle time does not match what you have saved.

  • @leonardozx
    @leonardozx 4 роки тому

    how can i use this "Time[0]", here it shows error

  • @babytigheyes
    @babytigheyes 5 років тому

    I have a project. Can you program for me a EA on mt4

    • @Jimdandy1958
      @Jimdandy1958  5 років тому

      I can. But I won't. If you want to learn how to write it then take the course at learnmql4.teachable.com or go to the mql5 freelance tab and get someone to code it for you. Best of luck... Pip Pip

    • @waynefilkins8394
      @waynefilkins8394 5 років тому

      Did you ever get it done?

  • @durgeshsharma7036
    @durgeshsharma7036 4 роки тому

    Good

  • @sherwincastro3998
    @sherwincastro3998 4 роки тому

    Hey Jim could you help me out with my coding problem. I applied your code to this(below). The code places a bid trade as it hit a certain price level. It is working except that it keeps placing a trade everytime it hits the assigned price level. I want it to just place a single trade thus your code should come in handy. However, still placing too many trades. This is MT4 by the way. Thanks.
    void ma1func()

    {

    static datetime candletime;
    if (Time [0]==candletime)
    return;
    double v_price3 = SymbolInfoDouble("XAUUSD",SYMBOL_BID);
    if ( v_price3 == SupportTargetPrice3 )

    {
    int buyticket = OrderSend(Symbol(),OP_BUY ,0.35 , Ask, 3,0,Ask+(2000*_Point),NULL,MAGICNUM_lcatcher,0,Green);
    }
    candletime=Time[0];
    }

    • @Jimdandy1958
      @Jimdandy1958  4 роки тому +1

      Before you place a trade check to see that a trade is not already open. If a trade is open you don't do an ordersend.

    • @sherwincastro3998
      @sherwincastro3998 4 роки тому

      @@Jimdandy1958 thanks I'll continue from that info.

  • @orbalerts1662
    @orbalerts1662 5 років тому

    What changes do I make, if I use this Indy on a M5 chart but need to chk new candle on M30 TF?

    • @Jimdandy1958
      @Jimdandy1958  5 років тому

      the zero after NULL denotes which timeframe you get the moving average of.. NULL,30... keep in mind that if you are using a 5m chart there will only be a new 30 minute number every 6 candles... Pip Pip

    • @ac24365
      @ac24365 4 роки тому

      @@Jimdandy1958 Hello Jim, What if I don't wish to calculate MA, but just need to calculate M30 candle close on a M5 chart. The indy will be on a M5 chart, but calculate M30 candle close. How to do that?

  • @kidhustler3184
    @kidhustler3184 5 років тому

    I want to know if it is possible to create a price action trading robot

    • @Jimdandy1958
      @Jimdandy1958  5 років тому +1

      hmmmm.... a price action trading robot..... instead of an EA that trades based on what?

  • @dovhaniramuthaga6506
    @dovhaniramuthaga6506 2 роки тому

    High i need help on my code

    • @Jimdandy1958
      @Jimdandy1958  2 роки тому

      go to the freelance section of mql5.com if you need help getting something coded.

  • @kirrs1
    @kirrs1 4 роки тому

    can i have your help?

  • @thembelssengwayo6896
    @thembelssengwayo6896 Рік тому

    I wonder if JimmyDady1958, is still alive. Hence he is nolonger producing new videos......or He became a billionaire and see no need to continue UA-cam......

  • @BGmedia
    @BGmedia 4 роки тому

    Dear Jim Maybe you can help me against payment i need an very simple indicator coded in mirror . So iT does exactly the oposite can you send me a personal message Please if you can help me

    • @Jimdandy1958
      @Jimdandy1958  4 роки тому

      for coding jobs go to mql5 's freelance section

    • @BGmedia
      @BGmedia 4 роки тому

      Jimdandy1958 Yes i understand But i dont trust everybody , And i have to have a good feeling about iT And your one of the few i have a good feeling with .

  • @paulekey7704
    @paulekey7704 6 років тому

    A Good video. Thank You !!!