New Strategy Idea In Development

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #100980 quote
    juanj
    Participant
    Master

    Hi Guys

    I love the idea of combining statistics and probability with my trading strategies so came up with the following idea;

    Considering a single timeframe and looking at how each individual candle is formed we will see that each candle starts with the opening price (previous closing price) then make both a high and a low and eventually settle with the closing price.

    This means that the majority of candles have some leg room between the opening price and it’s high and low. These wicks are usually referred to as the candle ‘shadow’

    So the basic idea here is to try and leverage this phenomenon by entering a trade at the opening price of a candle and scalping some points for a profit.

    To do this we need to first establish the statistical advantage or probability of the trade to succeed.

    This means we need to evaluate the current market condition by looking at some of the previous candles to see which direction to trade as well as how many points to target.

    We also need to take into consideration the spread and whether statistically speaking there are enough points to make the trade worthwhile.

    So here is what I have so far:

    Defparam cumulateorders = False
    
    //Timeframe: I am thinking that timeframes in the range of 5min to 1Day would work best
    //Market Hour Filter
    
    If (hour < 9 or (hour = 9 and minute <= 0)) or (hour > 17 or (hour = 17 and minute >= 0)) Then
    possize = 1 //Use 0 to enable filter
    If longonmarket Then
    Sell at market
    ElsIf shortonmarket Then
    Exitshort at market
    EndIf
    Else
    possize = 1
    EndIf
    
    //variables
    
    Spread = 1 //Enter spread here (For pips use format 0.0001)
    SpreadVar = 4 // Spread variance factor is used to establish whether there is enough volatility taking into account the market spread (optimize for values between 3-7)
    ShadowVar = 0.9 // Shadow variance factor is used to account for error in shadow length calculation (optimize for values between 0.8-0.9)
    RiskReward = 3 // Risk to reward ratio used to calculate stop loss (optimize for values between 1-3)
    StdDev = 1.2 // Standard deviation used to filter outliers (optimize for values between 1-2)
    EvalPeriod = 6 // Evaluation period that will be used to make estimations (optimize for values between 3-9)
    
    //Initialize Variables
    
    FollowHighGreenA = 0
    FollowLowGreenA = 0
    FollowHighRedA = 0
    FollowLowRedA = 0
    FGA = 0
    FRA = 0
    
    //Establish the length of upper and lower shadows for candles following both red and green candles in the evaluation period
    
    For i = 1 to EvalPeriod Do
    If close[i+1] > open[i+1] Then
    FollowHighGreenA = high[i] - open[i]
    FollowLowGreenA = open[i] - low[i]
    FGA = FGA + 1
    ElsIf close[i+1] < open[i+1] Then
    FollowHighRedA = high[i] - open[i]
    FollowLowRedA = open[i] - low[i]
    FRA = FRA + 1
    EndIf
    Next
    
    //Calculate the raw average values of the shadows
    
    FollowHighGreenB = FollowHighGreenA/FGA
    FollowLowGreenB = FollowLowGreenA/FGA
    FollowHighRedB = FollowHighRedA/FRA
    FollowLowRedB = FollowLowRedA/FRA
    
    //Test each shadow again similar to above but filter(cut) outliers against STD devaition
    
    For ii = 1 to EvalPeriod Do
    If close[ii+1] > open[ii+1] Then
    If high[ii] - open[ii] <= (StdDev*STD(FollowHighGreenB)) Then
    FollowHighGreenC = high[ii] - open[ii]
    Else
    FollowHighGreenC = (StdDev*STD(FollowHighGreenB))
    EndIf
    If open[ii] - low[ii] <= (StdDev*STD(FollowLowGreenB)) Then
    FollowLowGreenC = open[ii] - low[ii]
    Else
    FollowLowGreenC = (StdDev*STD(FollowLowGreenB))
    EndIf
    ElsIf close[ii+1] < open[ii+1] Then
    If high[ii] - open[ii] <= (StdDev*STD(FollowHighRedB)) Then
    FollowHighRedC = high[ii] - open[ii]
    Else
    FollowHighRedC = (StdDev*STD(FollowHighRedB))
    EndIf
    If open[ii] - low[ii] <= (StdDev*STD(FollowLowRedB)) Then
    FollowLowRedC = open[ii] - low[ii]
    Else
    FollowLowRedC = (StdDev*STD(FollowLowRedB))
    EndIf
    EndIf
    Next
    
    //Re-calculate the average values of the shadows
    
    FollowHighGreen = FollowHighGreenC/FGA
    FollowLowGreen = FollowLowGreenC/FGA
    FollowHighRed = FollowHighRedC/FRA
    FollowLowRed = FollowLowRedC/FRA
    
    //Validate entry conditions and set targets and stops
    
    If close > open and FollowHighGreen > FollowLowGreen and ((high - open)*ShadowVar) > (spread*SpreadVar) and ((FollowHighGreen*ShadowVar)/RiskReward) > (spread * SpreadVar) Then
    Buy possize contract at market
    Set target pprofit FollowHighGreen*ShadowVar
    Set stop ploss (FollowHighGreen*ShadowVar)/RiskReward
    ElsIf close > open and FollowHighGreen < FollowLowGreen and ((open - low)*ShadowVar) > (spread*SpreadVar) and ((FollowLowGreen*ShadowVar)/RiskReward) > (spread * SpreadVar) Then
    Sellshort possize contract at market
    Set target pprofit FollowLowGreen*ShadowVar
    Set stop ploss (FollowLowGreen*ShadowVar)/RiskReward
    ElsIf close < open and FollowHighRed > FollowLowRed and ((high - open)*ShadowVar) > (spread*SpreadVar) and ((FollowHighRed*ShadowVar)/RiskReward) > (spread * Spreadvar) Then
    Buy possize contract at market
    Set target pprofit FollowHighRed*ShadowVar
    Set stop ploss (FollowHighRed*ShadowVar)/RiskReward
    ElsIf close < open and FollowHighRed < FollowLowRed and ((open - low)*ShadowVar) > (spread*SpreadVar) and ((FollowLowRed*ShadowVar)/RiskReward) > (spread * spreadvar) Then
    Sellshort possize contract at market
    Set target pprofit FollowLowRed*ShadowVar
    Set stop ploss (FollowLowRed*ShadowVar)/RiskReward
    EndIf
    

    Improvements would include:

    Better ways to sample past candles and arrive at a more accurate ‘average’

    Additional filters to enhance probability i.e. volatility filter

    GraHal and winnie37 thanked this post
    #100983 quote
    GraHal
    Participant
    Master

    Wow! Great ideas there juanj !

    I hope some of the  coding wizards help you out with this!

    I’m already looking forward to checking it out tomorrow!

    Thank You for sharing thus far

    #101040 quote
    juanj
    Participant
    Master

    Thanks, Grahal, I also hope some of the old timers can jump onboard. I know @Vonasi have done some good work on probability analysis as well.

    One of the presumptions I made with the above is that it is useful to consider the color of the candle preceding the candle being analyzed. But thinking about it again last night I am not so sure this is valid. Will have to do a couple of tests.

    #101045 quote
    GraHal
    Participant
    Master

    Maybe colour + body size is the factor to look at and wick sizes and which side wick is the biggest. (You may already have done this as I’ve not had time to go over the code). 

    When manual trading one’s eyes take all these factors into account without even thinking. If one is asked why did you go Long at that point, often it’s like somebody asking … so why and how did you take a breath (breathe in)  just then! 🙂

    #101051 quote
    juanj
    Participant
    Master

    Just found a couple of mistakes in calculating the average as well as validating them against the spread. Here is the fix:

    Defparam cumulateorders = False
     
    //Timeframe: I am thinking that timeframes in the range of 5min to 1Day would work best
    //Market Hour Filter
     
    If (hour < 9 or (hour = 9 and minute <= 0)) or (hour > 17 or (hour = 17 and minute >= 0)) Then
    possize = 1 //Use 0 to enable filter
    If longonmarket Then
    Sell at market
    ElsIf shortonmarket Then
    Exitshort at market
    EndIf
    Else
    possize = 1
    EndIf
     
    //variables
     
    Spread = 1 //Enter spread here (For pips use format 0.0001)
    SpreadVar = 4 // Spread variance factor is used to establish whether there is enough volatility taking into account the market spread (optimize for values between 3-7)
    ShadowVar = 0.9 // Shadow variance factor is used to account for error in shadow length calculation (optimize for values between 0.8-0.9)
    RiskReward = 3 // Risk to reward ratio used to calculate stop loss (optimize for values between 1-3)
    StdDev = 1.2 // Standard deviation used to filter outliers (optimize for values between 1-2)
    EvalPeriod = 6 // Evaluation period that will be used to make estimations (optimize for values between 3-9)
     
    //Initialize Variables
     
    FollowHighGreenA = 0
    FollowLowGreenA = 0
    FollowHighRedA = 0
    FollowLowRedA = 0
    FGA = 0
    FRA = 0
     
    //Establish the length of upper and lower shadows for candles following both red and green candles in the evaluation period
     
    For i = 1 to EvalPeriod Do
    If close[i+1] > open[i+1] Then
    FollowHighGreenA = FollowHighGreenA + (high[i] - open[i])
    FollowLowGreenA = FollowLowGreenA  + (open[i] - low[i])
    FGA = FGA + 1
    ElsIf close[i+1] < open[i+1] Then
    FollowHighRedA = FollowHighRedA  + (high[i] - open[i])
    FollowLowRedA = FollowLowRedA  + (open[i] - low[i])
    FRA = FRA + 1
    EndIf
    Next
     
    //Calculate the raw average values of the shadows
     
    FollowHighGreenB = FollowHighGreenA/FGA
    FollowLowGreenB = FollowLowGreenA/FGA
    FollowHighRedB = FollowHighRedA/FRA
    FollowLowRedB = FollowLowRedA/FRA
    
    //Initialize Variables
     
    FollowHighGreenC = 0
    FollowLowGreenC = 0
    FollowHighRedC = 0
    FollowLowRedC = 0
     
    //Test each shadow again similar to above but filter(cut) outliers against STD devaition
     
    For ii = 1 to EvalPeriod Do
    If close[ii+1] > open[ii+1] Then
    If high[ii] - open[ii] <= (StdDev*STD(FollowHighGreenB)) Then
    FollowHighGreenC = FollowHighGreenC  + (high[ii] - open[ii])
    Else
    FollowHighGreenC = FollowHighGreenC + (StdDev*STD(FollowHighGreenB))
    EndIf
    If open[ii] - low[ii] <= (StdDev*STD(FollowLowGreenB)) Then
    FollowLowGreenC = FollowLowGreenC  + (open[ii] - low[ii])
    Else
    FollowLowGreenC = FollowLowGreenC + (StdDev*STD(FollowLowGreenB))
    EndIf
    ElsIf close[ii+1] < open[ii+1] Then
    If high[ii] - open[ii] <= (StdDev*STD(FollowHighRedB)) Then
    FollowHighRedC = FollowHighRedC + (high[ii] - open[ii])
    Else
    FollowHighRedC = FollowHighRedC + (StdDev*STD(FollowHighRedB))
    EndIf
    If open[ii] - low[ii] <= (StdDev*STD(FollowLowRedB)) Then
    FollowLowRedC = FollowLowRedC  + (open[ii] - low[ii])
    Else
    FollowLowRedC = FollowLowRedC  + (StdDev*STD(FollowLowRedB))
    EndIf
    EndIf
    Next
     
    //Re-calculate the average values of the shadows
     
    FollowHighGreen = FollowHighGreenC/FGA
    FollowLowGreen = FollowLowGreenC/FGA
    FollowHighRed = FollowHighRedC/FRA
    FollowLowRed = FollowLowRedC/FRA
     
    //Validate entry conditions and set targets and stops
     
    If close > open and FollowHighGreen > FollowLowGreen and (FollowHighGreen *ShadowVar) > (spread*SpreadVar) and ((FollowHighGreen*ShadowVar)/RiskReward) > (spread * SpreadVar) Then
    Buy possize contract at market
    Set target pprofit FollowHighGreen*ShadowVar
    Set stop ploss (FollowHighGreen*ShadowVar)/RiskReward
    ElsIf close > open and FollowHighGreen < FollowLowGreen and (FollowLowGreen *ShadowVar) > (spread*SpreadVar) and ((FollowLowGreen*ShadowVar)/RiskReward) > (spread * SpreadVar) Then
    Sellshort possize contract at market
    Set target pprofit FollowLowGreen*ShadowVar
    Set stop ploss (FollowLowGreen*ShadowVar)/RiskReward
    ElsIf close < open and FollowHighRed > FollowLowRed and (FollowHighRed *ShadowVar) > (spread*SpreadVar) and ((FollowHighRed*ShadowVar)/RiskReward) > (spread * Spreadvar) Then
    Buy possize contract at market
    Set target pprofit FollowHighRed*ShadowVar
    Set stop ploss (FollowHighRed*ShadowVar)/RiskReward
    ElsIf close < open and FollowHighRed < FollowLowRed and (FollowLowRed *ShadowVar) > (spread*SpreadVar) and ((FollowLowRed*ShadowVar)/RiskReward) > (spread * spreadvar) Then
    Sellshort possize contract at market
    Set target pprofit FollowLowRed*ShadowVar
    Set stop ploss (FollowLowRed*ShadowVar)/RiskReward
    EndIf
    #101056 quote
    juanj
    Participant
    Master

    So preliminary tests seem to show more robust performance when not considering candle colors and only looking at the average shadow lengths. I would appreciate any ideas on better sampling data to determine trade direction and profit targets.

    Defparam cumulateorders = False
     
    //Timeframe: I am thinking that timeframes in the range of 5min to 1Day would work best
    //Market Hour Filter
     
    If (hour < 9 or (hour = 9 and minute <= 0)) or (hour > 17 or (hour = 17 and minute >= 0)) Then
    possize = 1 //Use 0 to enable filter
    If longonmarket Then
    Sell at market
    ElsIf shortonmarket Then
    Exitshort at market
    EndIf
    Else
    possize = 1
    EndIf
     
    //variables
     
    Spread = 1 //Enter spread here (For pips use format 0.0001)
    SpreadVar = 4 // Spread variance factor is used to establish whether there is enough volatility taking into account the market spread (optimize for values between 3-7)
    ShadowVar = 0.9 // Shadow variance factor is used to account for error in shadow length calculation (optimize for values between 0.8-0.9)
    RiskReward = 3 // Risk to reward ratio used to calculate stop loss (optimize for values between 1-3)
    StdDev = 1.2 // Standard deviation used to filter outliers (optimize for values between 1-2)
    EvalPeriod = 6 // Evaluation period that will be used to make estimations (optimize for values between 3-9)
     
    //Initialize Variables
     
    HighA = 0
    LowA = 0
     
    //Establish the length of upper and lower shadows for candles following both red and green candles in the evaluation period
     
    For i = 1 to EvalPeriod Do
    HighA = HighA + (high[i] - open[i])
    LowA = LowA + (open[i] - low[i])
    Next
     
    //Calculate the raw average values of the shadows
     
    HighB = HighA/EvalPeriod
    LowB = LowA/EvalPeriod
     
    //Initialize Variables
     
    HighC = 0
    LowC = 0
     
    //Test each shadow again similar to above but filter(cut) outliers against STD devaition
     
    For ii = 1 to EvalPeriod Do
    If high[ii]-open[ii] <= (StdDev*STD(HighB)) Then
    HighC = HighC + (high[ii]-open[ii])
    Else
    HighC = HighC + (StdDev*STD(HighB))
    EndIf
    If open[ii] - low[ii] <= (StdDev*STD(LowB)) Then
    LowC = LowC + (open[ii] - low[ii])
    Else
    LowC = LowC + (StdDev*STD(LowB))
    EndIf
    Next
     
    //Re-calculate the average values of the shadows
     
    HighShadow = HighC/EvalPeriod
    LowShadow = LowC/EvalPeriod
     
    //Validate entry conditions and set targets and stops
     
    If HighShadow > LowShadow and (HighShadow*ShadowVar) > (spread*SpreadVar) and ((HighShadow*ShadowVar)/RiskReward) > (spread * SpreadVar) Then
    Buy possize contract at market
    Set target pprofit HighShadow*ShadowVar
    Set stop ploss (HighShadow*ShadowVar)/RiskReward
    ElsIf HighShadow < LowShadow and (LowShadow*ShadowVar) > (spread*SpreadVar) and ((LowShadow*ShadowVar)/RiskReward) > (spread * SpreadVar) Then
    Sellshort possize contract at market
    Set target pprofit LowShadow*ShadowVar
    Set stop ploss (LowShadow*ShadowVar)/RiskReward
    EndIf
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

New Strategy Idea In Development


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
juanj @juanj Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by juanj
6 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/18/2019
Status: Active
Attachments: No files
Logo Logo
Loading...