I have a trading idea, but I don't know how to execute it in python. I am not good at programming. I am trying to backtest my trading idea in PyCharm.
Please can anyone explain how I can write the codes that meet certain conditions written below?
First, I have to input certain parameters; the currency pair and a particular time. As an example: EURUSD and 9 AM EST.
Next, I have to define constants; PipBlock=10 (i.e 10 pips), DAYCounter=30 (i.e 30 trading days), PassCounter=0, FailCounter=0. 30 minutes candlestick chart is used. The program always starts at the 9 AM EST candle every trading day and analyzes for the past 30 tradings days.
It is important to know the meaning of the alphabet used in the trading scenarios below. The H means the high price of the current candle, O means the opening price of the first/initial candle, L means the low price of the current candle.
NOTE: If is analyzing any candle, It should retain the "Open" value of the initial candle(i.e if the 9 AM Open candle value is 1.1250 when analyzing the 2 PM EST candle, the program replaces the open value of that 2 PM EST candle with 1.1250 for the calculations). However, the High and Low values of any candle would not be replaced by the high/low of the initial candle values.
Now the logic for the trade has 4 possible scenarios:
if (H-O>PipBlock and O-L<PipBlock)
{PassCounter=PasCounter+1;}
#Then move to the next trading day
Explanation: The above is scenario 1, and it starts with the 9 AM candle. Then moves to the next 9 AM candle on the next day.
if (H-O<PipBlock and O-L<PipBlock)
#Move to the next candle, on the same trading day
Explanation: The Above is scenario 2, start with the 9 AM candle, then move to the 9:30 AM candle.
if (H-O<PipBlock and O-L>PipBlock)
#Move to the next candle, on the same trading day
Explanation: The Above is scenario 3, start with the 9 AM candle, then move to the 9:30 AM candle.
if (H-O>PipBlock and O-L>PipBlock)
#Move to the next candle, on the same trading day
Explanation: The Above is scenario 4, start with the 9 AM candle, then move to the 9:30 AM candle.
NOTE:
If any of scenario 2, 3, or 4 occurs first and secondly scenario 2 keeps occurring the program would keep moving from candle to candle(i.e 9 AM, 9:30 AM, 10 AM, 10:30 AM e.t.c) until the end of the trading day 9 PM EST then FailCounter=FailCounter+1 and the analysis ends for that trading day and moves to another trading day.
However, if scenario 3 or 4 occurs again at any time given that the first candle was any of scenarios 2, 3, or 4, then end the analysis immediately for that trading day and FailCounter=FailCounter+1, and move to another trading day.
If scenario 1 occurs at any time given that the first candle was any of scenarios 2, 3, or 4, then end the analysis immediately for that trading day and PassCounter=PassCounter+1, and move to another trading day.
Since DAYCounter is 30 days, once the program ends the analysis for a trading day, it would check for the same scenarios on another trading day. The program would keep doing this until the last 30 trading days are analyzed.
Finally after the 30 days analysis, Print the FailCounter and PassCounter values for that particular currency over the last 30 days.
Credit for contribution. Appreciated.
Please can anyone explain how I can write the codes that meet certain conditions written below?
First, I have to input certain parameters; the currency pair and a particular time. As an example: EURUSD and 9 AM EST.
Next, I have to define constants; PipBlock=10 (i.e 10 pips), DAYCounter=30 (i.e 30 trading days), PassCounter=0, FailCounter=0. 30 minutes candlestick chart is used. The program always starts at the 9 AM EST candle every trading day and analyzes for the past 30 tradings days.
It is important to know the meaning of the alphabet used in the trading scenarios below. The H means the high price of the current candle, O means the opening price of the first/initial candle, L means the low price of the current candle.
NOTE: If is analyzing any candle, It should retain the "Open" value of the initial candle(i.e if the 9 AM Open candle value is 1.1250 when analyzing the 2 PM EST candle, the program replaces the open value of that 2 PM EST candle with 1.1250 for the calculations). However, the High and Low values of any candle would not be replaced by the high/low of the initial candle values.
Now the logic for the trade has 4 possible scenarios:
if (H-O>PipBlock and O-L<PipBlock)
{PassCounter=PasCounter+1;}
#Then move to the next trading day
Explanation: The above is scenario 1, and it starts with the 9 AM candle. Then moves to the next 9 AM candle on the next day.
if (H-O<PipBlock and O-L<PipBlock)
#Move to the next candle, on the same trading day
Explanation: The Above is scenario 2, start with the 9 AM candle, then move to the 9:30 AM candle.
if (H-O<PipBlock and O-L>PipBlock)
#Move to the next candle, on the same trading day
Explanation: The Above is scenario 3, start with the 9 AM candle, then move to the 9:30 AM candle.
if (H-O>PipBlock and O-L>PipBlock)
#Move to the next candle, on the same trading day
Explanation: The Above is scenario 4, start with the 9 AM candle, then move to the 9:30 AM candle.
NOTE:
If any of scenario 2, 3, or 4 occurs first and secondly scenario 2 keeps occurring the program would keep moving from candle to candle(i.e 9 AM, 9:30 AM, 10 AM, 10:30 AM e.t.c) until the end of the trading day 9 PM EST then FailCounter=FailCounter+1 and the analysis ends for that trading day and moves to another trading day.
However, if scenario 3 or 4 occurs again at any time given that the first candle was any of scenarios 2, 3, or 4, then end the analysis immediately for that trading day and FailCounter=FailCounter+1, and move to another trading day.
If scenario 1 occurs at any time given that the first candle was any of scenarios 2, 3, or 4, then end the analysis immediately for that trading day and PassCounter=PassCounter+1, and move to another trading day.
Since DAYCounter is 30 days, once the program ends the analysis for a trading day, it would check for the same scenarios on another trading day. The program would keep doing this until the last 30 trading days are analyzed.
Finally after the 30 days analysis, Print the FailCounter and PassCounter values for that particular currency over the last 30 days.
Credit for contribution. Appreciated.