TRADE LIKE CASINO inspired by by Adam Khoo

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #53076 quote
    Leo
    Participant
    Veteran

    Hi all,

    Inspired by the videos and methodology from Adam Khoo (https://www.youtube.com/watch?v=bRCtBRsLPmk ) , I create this strategy using my indicator Leo Moving Average for detect local maximums and minimums.

    Although my code is universal  (for any market and any frame trade) Here is what I got, the strategy reflects my trading style: few money per trade to risk, small time frame, mini contract in IG.

    The strategy is simple: buy in support sell in resistance…. but:

    • When the ratio price-stoploss and price stopprofit is  higher than “Kcasino” which is a number more than one
    • When the trend is in favor (higher lows or lowers highs)
    • When the long term bias is in our favor

    I still not confident with the strategy because I like strategies with more winning ratios for using in real life.

    I hope we can all improve it.

    Cheers

    //TRADE LIKE CASINO
    //THIS IS A TRADING STRATEGY IN AREAS WHERE THE PROFIT/RISK RATIO IS HIGH THAN A VALUE (Kcasino) WHERE PROPABILITY IS IN THE FAVOR OF THE MOVEMENT
    //inspired by Adam Khoo
    //Autor: LEO
    
    DEFPARAM CumulateOrders = false // Cumulating positions deactivated
    DEFPARAM PreLoadBars = 3000 //cargar informacion
    
    //VARIABLES TO BE OPTIMIZED
    //period=20    //Period for analysis
    //Kcasino=1.75 //minimum profit/risk ratio between support and resistance
    //LongPeriod=1440 //Long term period for check bias
    //maxrisk=13 //max risk in pips for trade
    
    
    spread=0.7
    IF TIME < 060000 THEN //(germany time)
    spread=2*spread
    ELSIF TIME>213000 THEN //(germany time)
    spread=2*spread
    ENDIF
    
    totalrisk=4*maxrisk*n*PIPVALUE //for stop the robot if things are going bad
    
    //Robot Working Time (Germany)
    IF TIME>023000 and TIME < 210000 THEN
    ontime=1
    ELSE
    ontime=0
    ENDIF
    
    ////// RISK CONTROL IF THINGS ARE GOING WONDERFULL  //////
    n = 1 + (strategyprofit / (134*pipvalue))
    n = round(n * 100)
    n = n / 100
    n = max(1,n)
    
    //-----------
    
    //Leo Moving Average, formula: LMA= WMA+(WMA-SMA)
    LMA=2*weightedaverage[period](close)-average[period](close)
    
    //Smoothed curve of Leo Moving Average
    IF BARINDEX > period THEN
    smoothLMA=weightedaverage[period](LMA)
    ELSE
    smoothLMA=undefined
    ENDIF
    
    // Direction or trend of the LMA
    
    // << Storage of minimums and maximums >>
    once mintemp=low
    once posmintemp=1
    once maxtemp=high
    once posmaxtemp=1
    
    IF BARINDEX>2 THEN
    // the value 0.7 is to ensure that the donchian channel is faster than the curves analysis (this value to be checked)
    IF low < lowest[round(0.7*period)](low[1]) THEN
    mintemp=low //minimum temporal
    posmintemp=BARINDEX //postition of minimum temporal
    ENDIF
    IF high > highest[round(0.7*period)](high[1]) then
    maxtemp=high //maximum temporal
    posmaxtemp=BARINDEX //position maximum temporal
    ENDIF
    ENDIF
    
    //  << Detecting and locating a local minimums >>
    //  Where the LMA is crossing the smoothed LMA, there is a maximum or minimum nearby
    //  If there is a new local min/max, the preivus one is stored in de varible B... (before)
    once LEVMIN=low
    once POSLEVMIN=1
    once LEVMAX=high
    once POSLEVMAX=1
    once bullcross=0
    once bearcross=0
    
    IF BARINDEX > PERIOD THEN //For avoid computer errors
    bullcross=LMA crosses over smoothLMA
    bearcross=LMA crosses under smoothLMA
    ENDIF
    
    
    IF bullcross and POSLEVMIN<>posmintemp  THEN
    BBLEVMIN=BLEVMIN        // previus previus local minimum is saved
    //BBPOSLEVMIN=BPOSLEVMIN
    BLEVMIN=LEVMIN        //previus local minimum is saved
    //BPOSLEVMIN=POSLEVMIN
    LEVMIN=mintemp
    POSLEVMIN=posmintemp
    support=LEVMIN
    ENDIF
    
    // --> Detecting and locating a local maximum
    IF bearcross and POSLEVMAX<>posmaxtemp THEN
    BBLEVMAX=BLEVMAX       //previus local maximum is saved
    //BBPOSLEVMAX=BPOSLEVMAX
    BLEVMAX=LEVMAX       //previus local maximum is saved
    //BPOSLEVMAX=POSLEVMAX
    LEVMAX=maxtemp
    POSLEVMAX=posmaxtemp
    resistance=LEVMAX
    ENDIF
    
    once support=low
    once resistance=high
    support=min(low,support)
    resistance=max(high,resistance)
    
    //------------
    period2=LongPeriod
    //Leo Moving Average, formula: LMA= WMA+(WMA-SMA)
    LMA2=2*weightedaverage[period2](close)-average[period2](close)
    
    //Smoothed curve of Leo Moving Average
    IF BARINDEX > period2 THEN
    smoothLMA2=weightedaverage[period2](LMA)
    ELSE
    smoothLMA2=undefined
    ENDIF
    
    
    //LONG TRADES
    IF BBLEVMIN<BLEVMIN and BLEVMIN<LEVMIN and support=LEVMIN and close>smoothLMA THEN
    //higher lows, support has not been broken before and price is going up
    StopLossLong = (close-support)/pipsize + 2*spread //distance in pips for stoploss
    StopProfitLong = ((resistance+(resistance-support)*0.27)-close)/pipsize-2*spread //distance in pips to stopprofit (where an hippotetical support is brake until the fibbo expansion)
    IF StopProfitLong/StopLossLong > Kcasino THEN
    //the ratio between support and hipotetical brake of the next resistance is higher than Kcasino
    IF LMA2 > smoothLMA2 THEN //we have long term bias
    //HERE WE TRADE
    IF NOT LongOnMarket AND ontime=1 and StopLossLong<maxrisk THEN
    BUY n CONTRACTS AT MARKET
    SET STOP pLOSS StopLossLong
    SET TARGET pPROFIT StopLossLong*Kcasino
    ENDIF
    ENDIF
    ENDIF
    ENDIF
    
    //SHORT TRADES
    IF BBLEVMAX>BLEVMAX and BLEVMAX>LEVMAX and resistance=LEVMAX and close<smoothLMA THEN
    //lower highs, resistance have not been broken before and price going down
    StopLossShort=(resistance-close)/pipsize+2*spread
    StopProfitShort=(close-(support-(resistance-support)*0.27))/pipsize-2*spread
    IF StopProfitShort/StopLossShort > Kcasino THEN
    //the ratio between resistance and hipotetical brake of the next support is higher than Kcasino
    IF LMA2 < smoothLMA2 THEN //we have long term bias
    //HERE WE TRADE
    IF NOT ShortOnMarket AND ontime=1 and StopLossShort<maxrisk THEN
    SELLSHORT n CONTRACTS AT MARKET
    SET STOP pLOSS StopLossShort
    SET TARGET pPROFIT StopLossShort*Kcasino
    ENDIF
    ENDIF
    ENDIF
    ENDIF
    
    IF longonmarket then
    IF TIME > 224500 and DayOfWeek=5 then
    SELL AT MARKET
    ENDIF
    endif
    
    IF shortonmarket then
    IF TIME > 224500 and DayOfWeek=5 then
    EXITSHORT AT MARKET
    ENDIF
    endif
    
    //Quit the robot if things are going bad
    Q=MAX(Q,(STRATEGYPROFIT/pipvalue))
    R=Q-STRATEGYPROFIT/pipvalue
    IF R > totalrisk THEN
    QUIT
    ENDIF
    
    IF STRATEGYPROFIT < (-1*totalrisk) THEN
    QUIT
    ENDIF
    immo_vienna thanked this post
    #53085 quote
    Nicolas
    Keymaster
    Master

    Hi Leo, thank you very much for your post proposal in the library. I did not make a lot of tests about it but since it is mainly based upon optimized variables, and in order to maintain some kind of “quality” (to prevent discussions about overfitting, etc..), I’d prefer to publish it if you could make some robustness tests with the Walk Forward tool. If not that’s ok too, we can discuss about the strategy in this topic 🙂 Thank you again for your kindness.

    #53102 quote
    the_giorgio
    Participant
    Senior

    Is it possible to create a screener for swing trading with this ?

    #53202 quote
    Leo
    Participant
    Veteran

    I don’t work so much with screener

    Here I attached a WF in 1min timeframe

     

    #53221 quote
    Nicolas
    Keymaster
    Master
    Hi Leo, thanks for the WFA. The OOS WFE are not so great but not too bad too! So in this case I would advise to try more OOS periods to reduce the time the optimized variables are used for the strategy (1 month in 1 minute timeframe is a lot of bars). Good luck and have a nice Sunday 😉
    #53299 quote
    Leo
    Participant
    Veteran
    I try my best. I let you know if it improves
    #53899 quote
    Leo
    Participant
    Veteran

    Hi all,

    I got this code:

    • The code calculates and stores local max and min with a LMA indicator using “period”
    • The code also looking for local max and min with a faster LMA using “period3”
    • Entry long conditions are (for short are opposite)
    1. When there are higher lows and higher highs and the price is situated in a zone where stop and resistance has a ratio of Casino(>1)
    2. It is according to a long period moving average

    I hope you like the code, I am very optimistic because is like trading manual but with a computer…. but  somehow I am not fully satisfied. I think there should be another type  of indicator for filtering/confirm the entry.

    Can you tell me your opinions ?

    //TRADE LIKE CASINO v1.2
    //THIS IS A TRADING STRATEGY IN AREAS WHERE THE PROFIT/RISK RATIO IS HIGH THAN A VALUE (Kcasino) WHERE PROPABILITY IS IN THE FAVOR OF THE MOVEMENT
    //inspired by Adam Khoo
    //Autor: LEO
    
    DEFPARAM CumulateOrders = false // Cumulating positions deactivated
    DEFPARAM PreLoadBars = 3000 //cargar informacion
    
    //VARIABLES TO BE OPTIMIZED
    //period=20    //Period for analysis
    //Kcasino=1.75 //minimum profit/risk ratio between support and resistance
    //LongPeriod=1440 //Long term period for check bias
    //maxrisk=13 //max risk in pips for trade
    //Kperiod=0.5 //
    
    
    spread=0.7
    IF TIME < 060000 THEN //(germany time)
    spread=2*spread
    ELSIF TIME>213000 THEN //(germany time)
    spread=2*spread
    ENDIF
    
    totalrisk=4*maxrisk*n*PIPVALUE //for stop the robot if things are going bad
    
    //Robot Working Time (Germany)
    IF TIME>023000 and TIME < 210000 THEN
    ontime=1
    ELSE
    ontime=0
    ENDIF
    
    ////// RISK CONTROL IF THINGS ARE GOING WONDERFULL  //////
    n = 1 + (strategyprofit / (134*pipvalue))
    n = round(n * 100)
    n = n / 100
    n = max(1,n)
    
    //-----------
    
    //Leo Moving Average, formula: LMA= WMA+(WMA-SMA)
    LMA=2*weightedaverage[period](close)-average[period](close)
    
    //Smoothed curve of Leo Moving Average
    IF BARINDEX > period THEN
    smoothLMA=weightedaverage[period](LMA)
    ELSE
    smoothLMA=undefined
    ENDIF
    
    // Direction or trend of the LMA
    
    // << Storage of minimums and maximums >>
    once mintemp=low
    once posmintemp=1
    once maxtemp=high
    once posmaxtemp=1
    
    IF BARINDEX>2 THEN
    // the value 0.7 is to ensure that the donchian channel is faster than the curves analysis (this value to be checked)
    IF low < lowest[round(0.7*period)](low[1]) THEN
    mintemp=low //minimum temporal
    posmintemp=BARINDEX //postition of minimum temporal
    ENDIF
    IF high > highest[round(0.7*period)](high[1]) then
    maxtemp=high //maximum temporal
    posmaxtemp=BARINDEX //position maximum temporal
    ENDIF
    ENDIF
    
    //  << Detecting and locating a local minimums >>
    //  Where the LMA is crossing the smoothed LMA, there is a maximum or minimum nearby
    //  If there is a new local min/max, the preivus one is stored in de varible B... (before)
    once LEVMIN=low
    once POSLEVMIN=1
    once LEVMAX=high
    once POSLEVMAX=1
    once bullcross=0
    once bearcross=0
    
    IF BARINDEX > PERIOD THEN //For avoid computer errors
    bullcross=LMA crosses over smoothLMA
    bearcross=LMA crosses under smoothLMA
    ENDIF
    
    
    IF bullcross and POSLEVMIN<>posmintemp  THEN
    //BBLEVMIN=BLEVMIN        // previus previus local minimum is saved
    //BBPOSLEVMIN=BPOSLEVMIN
    BLEVMIN=LEVMIN        //previus local minimum is saved
    //BPOSLEVMIN=POSLEVMIN
    LEVMIN=mintemp
    POSLEVMIN=posmintemp
    support=LEVMIN
    ENDIF
    
    // --> Detecting and locating a local maximum
    IF bearcross and POSLEVMAX<>posmaxtemp THEN
    //BBLEVMAX=BLEVMAX       //previus local maximum is saved
    //BBPOSLEVMAX=BPOSLEVMAX
    BLEVMAX=LEVMAX       //previus local maximum is saved
    //BPOSLEVMAX=POSLEVMAX
    LEVMAX=maxtemp
    POSLEVMAX=posmaxtemp
    resistance=LEVMAX
    ENDIF
    
    once support=low
    once resistance=high
    support=min(low,support)
    resistance=max(high,resistance)
    
    ///////////////////////////////////////////////////
    //------------------------------------------------
    period3=round(Kperiod*period)
    //Leo Moving Average, formula: LMA= WMA+(WMA-SMA)
    LMA3=2*weightedaverage[period3](close)-average[period3](close)
    
    //Smoothed curve of Leo Moving Average
    IF BARINDEX > period3 THEN
    smoothLMA3=weightedaverage[period3](LMA3)
    ELSE
    smoothLMA3=undefined
    ENDIF
    
    // Direction or trend of the LMA
    
    // << Storage of minimums and maximums >>
    once mintemp3=low
    once posmintemp3=1
    once maxtemp3=high
    once posmaxtemp3=1
    
    IF BARINDEX>2 THEN
    // the value 0.7 is to ensure that the donchian channel is faster than the curves analysis (this value to be checked)
    IF low < lowest[round(0.7*period3)](low[1]) THEN
    mintemp3=low //minimum temporal
    posmintemp3=BARINDEX //postition of minimum temporal
    ENDIF
    IF high > highest[round(0.7*period3)](high[1]) then
    maxtemp3=high //maximum temporal
    posmaxtemp3=BARINDEX //position maximum temporal
    ENDIF
    ENDIF
    
    //  << Detecting and locating a local minimums >>
    //  Where the LMA is crossing the smoothed LMA, there is a maximum or minimum nearby
    //  If there is a new local min/max, the preivus one is stored in de varible B... (before)
    once LEVMIN3=low
    //once POSLEVMIN3=1
    once LEVMAX3=high
    //once POSLEVMAX3=1
    once bullcross3=0
    once bearcross3=0
    
    IF BARINDEX > PERIOD3 THEN //For avoid computer errors
    bullcross3=LMA3 crosses over smoothLMA3
    bearcross3=LMA3 crosses under smoothLMA3
    ENDIF
    
    
    IF bullcross3 and POSLEVMIN3<>posmintemp3  THEN
    //BLEVMIN3=LEVMIN3        //previus local minimum is saved
    //BPOSLEVMIN3=POSLEVMIN3
    LEVMIN3=mintemp3
    POSLEVMIN3=posmintemp3
    support3=LEVMIN3
    ENDIF
    
    // --> Detecting and locating a local maximum
    IF bearcross3 and POSLEVMAX3<>posmaxtemp3 THEN
    //BLEVMAX3=LEVMAX3       //previus local maximum is saved
    //BPOSLEVMAX3=POSLEVMAX3
    LEVMAX3=maxtemp3
    POSLEVMAX3=posmaxtemp3
    resistance3=LEVMAX3
    ENDIF
    
    support3=min(low,support3)
    resistance3=max(high,resistance3)
    
    
    ////////////////// LONG TERM BIAS /////////////
    //------------
    period2=LongPeriod
    //Leo Moving Average, formula: LMA= WMA+(WMA-SMA)
    LMA2=2*weightedaverage[period2](close)-average[period2](close)
    
    //Smoothed curve of Leo Moving Average
    IF BARINDEX > period2 THEN
    smoothLMA2=weightedaverage[period2](LMA)
    ELSE
    smoothLMA2=undefined
    ENDIF
    
    
    //LONG TRADES
    IF BLEVMIN<LEVMIN and LEVMIN<LEVMIN3 and support=LEVMIN and close>smoothLMA3 and BLEVMAX<LEVMAX THEN
    //higher lows, support has not been broken before and price is going up
    StopLossLong = (close-support3)/pipsize + 2*spread //distance in pips for stoploss
    StopProfitLong = (resistance-close)/pipsize-4*spread //distance in pips to stopprofit (where an hippotetical support is brake until the fibbo expansion)
    IF StopProfitLong/StopLossLong > Kcasino THEN
    //the ratio between support and hipotetical brake of the next resistance is higher than Kcasino
    IF LMA2 > smoothLMA2 THEN //we have long term bias
    //HERE WE TRADE
    IF NOT LongOnMarket AND ontime=1 and StopLossLong<maxrisk THEN
    BUY n CONTRACTS AT MARKET
    SET STOP pLOSS StopLossLong
    SET TARGET pPROFIT StopLossLong*(Kcasino-0.25)
    ENDIF
    ENDIF
    ENDIF
    ENDIF
    
    //SHORT TRADES
    IF BLEVMAX>LEVMAX and LEVMAX>LEVMAX3 and resistance=LEVMAX and close<smoothLMA3 and BLEVMIN > LEVMIN THEN
    //lower highs, resistance have not been broken before and price going down
    StopLossShort=(resistance3-close)/pipsize+2*spread
    StopProfitShort=(close-support)/pipsize-4*spread
    IF StopProfitShort/StopLossShort > Kcasino THEN
    //the ratio between resistance and hipotetical brake of the next support is higher than Kcasino
    IF LMA2 < smoothLMA2 THEN //we have long term bias
    //HERE WE TRADE
    IF NOT ShortOnMarket AND ontime=1 and StopLossShort<maxrisk THEN
    SELLSHORT n CONTRACTS AT MARKET
    SET STOP pLOSS StopLossShort
    SET TARGET pPROFIT StopLossShort*(Kcasino-0.25)
    ENDIF
    ENDIF
    ENDIF
    ENDIF
    
    IF longonmarket then
    IF TIME > 224500 and DayOfWeek=5 then
    SELL AT MARKET
    ENDIF
    endif
    
    IF shortonmarket then
    IF TIME > 224500 and DayOfWeek=5 then
    EXITSHORT AT MARKET
    ENDIF
    endif
    
    //Quit the robot if things are going bad
    Q=MAX(Q,(STRATEGYPROFIT/pipvalue))
    R=Q-STRATEGYPROFIT/pipvalue
    IF R > totalrisk THEN
    QUIT
    ENDIF
    
    IF STRATEGYPROFIT < (-1*totalrisk) THEN
    QUIT
    ENDIF
    

     

    Fabiano thanked this post
    #54009 quote
    Leo
    Participant
    Veteran

    EUR/USD in 5min the system is promising.

    It is possible, someone of you can tested with 200K bars. Thanks

     

    #54032 quote
    rejo007
    Participant
    Senior

    It’s extremely long to run backtest on this strategy.

    Do you have the same problem?

    #54273 quote
    Leo
    Participant
    Veteran
    I tried my best for optimizing the code but the mathematics inside I think is the issue.
    #72574 quote
    Kate
    Participant
    New
    HI Thank you for sharing your idea. When I want to compile it, I have errors in these too lines   DEFPARAM CumulateOrders = false // Cumulating positions deactivated   and   the last ENDIF   would you please help me to solve it? I am working with MQL5 editor.   looking forward to you Thank you
    #72600 quote
    Vonasi
    Moderator
    Master
    Kate -This is a forum dedicated to coding for the ProRealTime platform  Support for MQL5 is not offered here.
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

TRADE LIKE CASINO inspired by by Adam Khoo


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Leo @leito Participant
Summary

This topic contains 11 replies,
has 6 voices, and was last updated by Vonasi
7 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/17/2017
Status: Active
Attachments: 6 files
Logo Logo
Loading...