Stopping trading after crossing balance

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #179171 quote
    egyptiantrader
    Participant
    Junior

    Hi all.

    I want to add some code that checks to see if the price is moving above or below a zone perhaps increasing a counter than can be then referred to to stop trading if it’s over a certain number in the last x amount of candles.

    The counter must only increase when the price goes from on side to the other not if it goes into the green box and back out the same side.

    Thanks in advance.

    Screenshot-2021-10-07-09.20.35.png Screenshot-2021-10-07-09.20.35.png
    #179258 quote
    robertogozzi
    Moderator
    Master

    There you go:

    Periods = 40
    Bullish = close > open
    Bearish = close < open
    HH      = highest[Periods](close)
    LL      = lowest[Periods](close)
    Rng     = (HH - LL) / 4
    IF (HH <> HH[1]) OR (LL <> LL[1]) THEN
       Tally = 0
    ENDIF
    HItouch = high >= HH
    LOtouch = low  <= LL
    IF HItouch AND Bullish THEN
       Tally = Tally + 1
       DrawText("#Tally#",BarIndex,HH + Rng)
    ENDIF
    IF LOtouch AND Bearish THEN
       Tally = Tally + 1
       DrawText("#Tally#",BarIndex,LL - Rng)
    ENDIF
    RETURN HH AS "Top",LL AS "Bottom"

    The count is cleared anytime one of the two limits changes.
    You can embed this code in your strategy (without the last line) and make your trading decisions according to the value retained by TALLY.

    GraHal, egyptiantrader and Midlanddave thanked this post
    x-5.jpg x-5.jpg
    #179261 quote
    GraHal
    Participant
    Master

    Link to above added as Log 307 here …

    Snippet Link Library

    robertogozzi thanked this post
    #179262 quote
    robertogozzi
    Moderator
    Master

    You can also try replacing lines 4-5 with:

    HH      = highest[Periods](max(open,close))
    LL      = lowest[Periods](min(open,close))

    This will make limits change a bit more frequently, thus clearing the count more often.

    #179399 quote
    egyptiantrader
    Participant
    Junior

    Thank you.

    Would it be possible to not reset the counter if the price goes in then out of the same side?  I don’t want it to add to the counter but I also don’t want it to reset.

    To be clear I want the counter to increase each time the price goes from one side to the other in a given period.

    I have the variables “upper” and Lower set in the code I assume I can just switch HH and LL for my terms?

    Thank you for your help, I really appreciate it.

    #179572 quote
    robertogozzi
    Moderator
    Master

    There you go:

    ONCE Periods   = 20
    ONCE Alternate = 1   //1=only alternate touches,   0=all touches
    ONCE HItouch   = 0
    ONCE LOtouch   = 0
    ONCE LastType  = 0   //1=HItouch,  -1=LOtouch
    Bullish        = close > open
    Bearish        = close < open
    HH             = highest[Periods](close)  //highest[Periods](max(open,close))
    LL             = lowest[Periods](close)   //lowest[Periods](min(open,close))
    IF (HH <> HH[1]) OR (LL <> LL[1]) THEN
       Tally       = 0
       LastType    = 0
    ENDIF
    Rng            = (HH - LL) / 4
    HItouch        = high >= HH
    LOtouch        = low  <= LL
    IF HItouch THEN
       LastType    = 1
    ELSIF LOtouch THEN
       LastType    = -1
    ENDIF
    IF HItouch AND Bullish AND LastType = 1 AND ((Tally = 0) OR (Not Alternate) OR (Alternate AND (LastType <> 1))) THEN
       Tally       = Tally + 1
       DrawText("#Tally#",BarIndex,HH + Rng)
    ENDIF
    IF LOtouch AND Bearish AND LastType = -1 AND ((Tally = 0) OR (Not Alternate) OR (Alternate AND (LastType <> -1))) THEN
       Tally       = Tally + 1
       DrawText("#Tally#",BarIndex,LL - Rng)
    ENDIF
    RETURN HH AS "Top",LL AS "Bottom"

    I think this won’t be useful as it is coded, since it hardly counts higher than 1.
    You need to define another way to spot the area, other than using close (I used CLOSE as you posted no hints about the definition of that area).

    egyptiantrader thanked this post
    #179654 quote
    egyptiantrader
    Participant
    Junior

    Thanks. I should be able to adjust to fit into my algo.

    Can you recommend a good teacher/course/tutorials where I can improve my coding? I’m about halfway through the advanced course and it’s getting to the stage where it’s becoming hard to follow without having exercises etc to practice the previous chapters.

    I’m only about a month into coding, I feel like I’m maybe missing some background knowledge on concepts etc.

    #179662 quote
    robertogozzi
    Moderator
    Master

    Sorry, I don’t know of any course.

    Maybe you can find some on the Marketplace https://market.prorealcode.com/?prcmaf=9f7907cc&from=home.

    egyptiantrader thanked this post
    #179707 quote
    GraHal
    Participant
    Master

    Maybe you are trying to get in too deep too quick?

    Have you coded up a simple strategy all on your own?

    Using the Assisted Creation tool is good also as then you can see what the code should be and you can then duplicate a System and modify it.  If your modified system system does not run, you can easily compare to the original system which will still run etc.

    egyptiantrader thanked this post
    #179981 quote
    egyptiantrader
    Participant
    Junior

    Hi. I have created several simple systems and got them working as expected. I now want to move on to more advanced coding/concepts that i can use to create a profitable strategy. I think this would be a much quicker process with a mentor/tutor or a course that had some problems/questions set that needed to be coded and feedback on the code you produce.

    Maybe a programming course that uses a different language with the same concepts?

    #179987 quote
    GraHal
    Participant
    Master
    #179997 quote
    GraHal
    Participant
    Master

    Idea for you … have a go at coding these two strategies and then compare your code to what is / will be provided by our resident and kind Coding Wizard Roberto?

    https://www.prorealcode.com/topic/coding-request-for-ema9-wma30-strategy/

    https://www.prorealcode.com/topic/ea-with-multiple-bb/#post-179993

    egyptiantrader and robertogozzi thanked this post
    #180000 quote
    egyptiantrader
    Participant
    Junior

    Yes I saw those courses but i was looking for recommendations and maybe something a bit more comprehensive.

    #180001 quote
    egyptiantrader
    Participant
    Junior

    Thanks, I’ll give it a go. Should be interesting/funny what I come up with compared to Roberto and I’m sure I’ll learn something. Great suggestion, thanks.

    GraHal thanked this post
Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.

Stopping trading after crossing balance


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 13 replies,
has 3 voices, and was last updated by egyptiantrader
4 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/07/2021
Status: Active
Attachments: 2 files
Logo Logo
Loading...