Basic ----- Strategy Introduction --------------------- We have to write TradingView strategy script. We must be able to test this strategy in TradingView with built in strategy tester panel. https://snipboard.io/Ma5b1w.jpg This strategy will be based on Hakin Ashi candle. Based on Hakin Ashi candle we will take entry and exit. https://snipboard.io/jRF7eY.jpg User Input --------------------- We will ask these values from users like this https://snipboard.io/eCRX0T.jpg There will be "LevelValue" variable which will be in percentage like 0.25%,0.5% and 1% default value will be 0.5% There will be "TrendValue" which value will be in percentage like 0.25%,0.5% and 1% default value will be 0.5%. There will be "Segment" variable which's value will be MCX or NSE like dropdown. Default NSE. There will be "ExpiryExitTime" variable default value will be 11 AM. Internal Variables ----------------- These variables will be in code only. There will be 2 expiry array, one will be for "MCXExpiry" and Another one will be for "NSEExpiry" this array will hold the list of Dates. We will add values in this array in scripts and it values will be like 25/Jan/2020,25/Feb/2020,26/Mar/2020. There will be one variable called "CurrentTrend", And its value will be Green or Red. Strategy Description -------------------- 1. Identify the Trend Based on Hakin Ashi candles first we have to Identify the trend and update the "CurrentTrend" variable. On closing of every candle we will check if Candle color and CurrentTrend variable value is not same. e.g. Candle color is Green and CurrentTrend value is Red then will perform the below check. If High and Low Diff of candle is greater than TrendValue value e.g High = 15720 and Low=15600 then diff will be 120 points and CMP = 15710 then DIFF x 100 / CMP means 120 x 100 / 15710 = 0.76 which is greater then TrendValue (0.5 here in the case) then we will update CurrentTrend variable based on candle color. https://snipboard.io/6zotju.jpg see here for this green candle is variable will be updated "CurrentTrend" variable to "Green". Note: Here High and Low value will be based on Hakin Ashi candle. CMP means price of stock at that moment. Generally once candle is closed then will run this check. like candle duration is 5 minute then every 5 minute will check if TrendValue is changed or not. 2. Entry for Reverse Call Once CurrentTrend variable is changed from Red to Green or vice versa. We will generate the Call. If CurrentTrend is Green then we will take Short(Sell) position. If CurrentTrend is Red then we will take Long(Buy) position. Here SL of these calls will be based on LevelValue. Here is the formula for the same. Lets say we taken long position at 15700 then SL will be CMP - ((CMP x LevelValue)/100) = 15700 - ((15700 x 0.5)/100) = 15621.5 For Sell, Formula will be CMP + ((CMP x LevelValue)/100) = 15700 + ((15700 x 0.5)/100) = 15778.5 Here we have to setup the call note e.g. this one https://snipboard.io/Nrin2V.jpg signal column. Here when we enter for short call then Note of call will be "ShortEntry-Reverse" and for buy call it will be "LongEntry-Reverse". Note: Before generating Buy or Sell call, just make sure CanGenerateNewCall() fuction return true. Defination of this fuction given below. 3. Exit for Reverse Call 3.1 Exit when SL hit. For SL I have mentioned above formula. Here call notes will be for Short Call "ShortExit-Reverse-SLHit". For buy Call "LongExit-Reverse-SLHit". 3.2 Exit when CurrentTrend value is changed. Here call notes will be for Short Call "ShortExit-Reverse-TrendChanged". For buy Call "LongExit-Reverse-TrendChanged". 4. Entry for Same Call As in point number 2, When CurrentTrend is Green we have taken the Short(Sell) position. If SL hit for this call then We will take Buy Position. Similarly, as in point number 2, When CurrentTrend is Red we have taken the Long(Buy) position, If SL hit for this call then we take Sell position. SL for these calls will be For Long(Buy) position, CMP - ((CMP x 2 x LevelValue)/100) = 15800 - ((15800 x 2 x 0.5)/100) = 15642 SL for these calls will be For Short(Sell) position, CMP + ((CMP x 2 x LevelValue)/100) = 15800 + ((15800 x 2 x 0.5)/100) = 159858 Here when we enter for short call then Note of call will be "ShortEntry-Same" and for buy call it will be "LongEntry-Same". Note: Before generating Buy or Sell call, just make sure CanGenerateNewCall() fuction return true. Defination of this fuction given below. 5. Exit for Same Call 5.1 Exit when SL hit. Here call notes will be for Short Call "ShortExit-Reverse-SLHit". For buy Call "LongExit-Reverse-SLHit". 5.2 Exit when Trend Value is changed. Here call notes will be for Short Call "ShortExit-Reverse-TrendChanged". For buy Call "LongExit-Reverse-TrendChanged". 6. Exit on Contract Expiry Day Based on the value of Segment, If selected value is NSE then consider NSEExpiry array or if selected value is MCX then consider MCXExpiry array. if Today value matches with Array then at close the any running call at "ExpiryExitTime" time. Here call Exit Note will be For buy Call "LongExit-ContractEnd" For sell call "ShortExit-ContractEnd" CanGenerateNewCall() Function Before generating new call we will check, Based on the value of Segment, If selected value is NSE then consider NSEExpiry array or if selected value is MCX then consider MCXExpiry array. If Today's date value matches with Array then return false.