strategy help

Questions about MultiCharts and user contributed studies.
leonng
Posts: 6
Joined: 15 Aug 2023

strategy help

Postby leonng » 15 Aug 2023

Hi, I asked chatgpt to help me. I am trying to do a trading sessions for 65 minute bars on stocks. A simple RSI zero crossing it goes long/short. For stocks like google, there are a 6x 65 minutes in a day. So one session is 4 trading days starting at the first day of the month, the next session is a the 5th-9th trading day of the month, etc. . There are 4x6 or 24 bars per trading session.

Unfortunately, no trades are actually executed. Anyone have an idea how to do this?

Code: Select all

Inputs: BegDate(1210101), EndDate(1231231), RsiLength(14), CandlesPerSession(6); // Number of candles per session Vars: RsiValue(0), LongEntry(False), ShortEntry(False), BarsSinceEntry(0), SessionCounter(0), BarsSinceSession(0), SessionStartBar(0), TradingDaysInMonth(0), CurrentTradingDay(0); if DateToJulian(Date) >= BegDate and DateToJulian(Date) <= EndDate then begin RsiValue = RSI(Close, RsiLength); // Count the number of trading days in the month if Month(Date) <> Month(Date[1]) then begin TradingDaysInMonth = 1; CurrentTradingDay = 1; end else if DayOfWeek(Date) <> DayOfWeek(Date[1]) then begin TradingDaysInMonth = TradingDaysInMonth + 1; CurrentTradingDay = CurrentTradingDay + 1; end; // Calculate the starting bar of each session SessionStartBar = (CurrentTradingDay - 1) * CandlesPerSession * 4 + 1; // Check if the session has started if BarNumber >= SessionStartBar then BarsSinceSession = BarNumber - SessionStartBar + 1; // Long entry condition: RSI crosses above zero LongEntry = crosses_above(RsiValue, 0); // Short entry condition: RSI crosses below zero ShortEntry = crosses_below(RsiValue, 0); if LongEntry then begin Buy next bar at market; BarsSinceEntry = 0; end else if ShortEntry then begin SellShort next bar at market; BarsSinceEntry = 0; end else begin BarsSinceEntry = BarsSinceEntry + 1; if BarsSinceSession >= CandlesPerSession * 4 then begin BarsSinceSession = 0; if MarketPosition = 1 then Sell next bar at market else if MarketPosition = -1 then BuyToCover next bar at market; end; end; end;

User avatar
hb7of9
Posts: 18
Joined: 23 Apr 2014
Has thanked: 9 times
Been thanked: 3 times

Re: strategy help

Postby hb7of9 » 15 Sep 2023

I've tried ChatGPT for input on EasyLanguage, and its code out is utter trash, as in it never works or gives completely incorrect advice, you'd tell it why XYZ is incorrect and then it'll agree that's incorrect, but 2 minutes later give you the same incorrect code response.

The best would be to break your code apart into sections, make it simpler and from there determine what works/doesn't work.

leonng
Posts: 6
Joined: 15 Aug 2023

Re: strategy help

Postby leonng » 24 Sep 2023

Thanks...yeah i think i kind of know where the problem is. the date and time are sort of not acting as what i expected. maybe i have to use another reference word that includes both date and time together. ah well. tough and slow. sigh.

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: strategy help

Postby rrams » 25 Sep 2023

leonng,

That is a somewhat unusual exit style. If I understand correctly, you want to enter at any RSI cross-over, but only exit every fourth day of the month? So you might be in the trade one bar or up to 24 bars?

MC trading sessions are defined by hours of the week and cannot span days of the month so lets call this a trading window or something. The session you are using is 9:30am-4:00pm I assume.

A zero RSI value is probably not what you want. Did you mean 50? I will use the standard 70 and 30.

Code: Select all

// RSI CrossOver entry on 65 min bars 9:30am-4:00pm session. // Exit based on a 4 trading day segment of the month. input: RsiLength(14); vars: TradingDays(0), // not weekends or holidays RsiValue(0), LongEntry(False), ShortEntry(False); RsiValue=RSI(C, RsiLength); // Long entry condition: RSI crosses above 70. LongEntry=crosses_above(RsiValue, 70); // Short entry condition: RSI crosses below 30. ShortEntry=crosses_below(RsiValue, 30); // Enter at any time RSI crosses. if LongEntry then Buy next bar market else if ShortEntry then SellShort next bar market; // Accumulate bars to represent 4 trading days. if Month(D)<>Month(D[1]) then TradingDays=1 else TradingDays+=1; // Exit every 4th trading day (24 bars) of the month. if Floor(TradingDays/24)<>Floor(TradingDays[1]/24) then begin if MarketPosition=1 then Sell next bar market; if MarketPosition=-1 then BuyToCover next bar market; end; print(TradingDays:0:0, " RSI: ", RsiValue:0:0);
Is this close to what you had envisioned?


Return to “MultiCharts”