Trying to Develop a...
 
Notifications
Clear all

Trying to Develop a System..(Need Help)

6 Posts
2 Users
0 Likes
395 Views
gab.jornacion
(@gab-jornacion)
Posts: 5
Active Member User
Topic starter
 

Hi Guys,

So we've just discovered this wonderful software and been trying to develop a trading system. 
When we try to backtest this, it seems that it's trading fairly low(we set the time to 1yr) also, if I check it on the stock charts, it seems to not get ALL of the buy signals that were supposed to be compliant with our conditions.

 

Here are the conditions:

Buy Signal
#1) Green Candle
#2) Green Volume - Above 5M pesos
#3) Above MA20

Sell Signal
#1) Red Candle
#2) Red Volume - Sellers are dominant
#3) Below MA20

Attached is the code that I made. (EDIT: Di pala na-attach, see below for the code)

Here is a screenshot of an example where it didn't show any buy or sell signals: https://drive.google.com/file/d/1KTUXAKnbLbfDj4_oNhvsddAY9NYnvHLn/view?usp=sharing

(It's a google drive link)

 

I'm not entirely sure if I even did the code correctly for the parameters, so I hope you can help me correct anything from this. 😀

Anyway, what I've tried so far is adjusting the BreakHigh/Low value and even the BreakOut/Down Signal value. There are still parts of the charts that don't show any signals. 

Hope you can help me with this! 🙂 

 

 

//File name: STS_kgj_position.ts
//Developer: Gabster
//Date created: 20210422
//Script description:
// Script for Short Term
// Below are the conditions need to fulfill for short term buy/sell signals
#######################################################################################################
#1) Green Candle
#2) Green Volume - Above 5M pesos
#3) Above MA20 
#5) MACD crosses above its signal line ? Bullish confirmation need to be patterned with MA20
#6) At Support
#######################################################################################################

#Set MA20 and Plot Line 
Set ma20 = sma(close,20)
plot(ma20,line,red,main)


#Set Candle Status
Set IsGreen = Close > Open
Set IsRed = Close < Open

#Check green volume
SET isVolumeGreen = VOLUME > 5000000 AND isGreen
Set isVolumeRedWith5M = VOLUME > 5000000 AND isRed

#Check if Candle is Above MA20
Set isAboveMA20 = LAST > ma20
Set isBelowMA20 = LAST <ma20

#Breakout

Set Breakhigh = max(high,1)
Set Breaklow = min(low,1)
Set Breakoutsignal = close > ref(breakhigh,1)
Set Breakdownsignal = close < ref(breaklow,1)

#plot(breakhigh,step,green,main)
#plot(breaklow,step,red,main)

Set BuyMe = isGreen AND isVolumeGreen AND isAboveMA20 and  Breakoutsignal
Set SellMe = isRed AND isBelowMA20

#PlotSignals
plotbuysell(BuyMe,SellMe, Green, Red, Main)
#plot(SellMe, Sell, Green, Main)

signals(BuyMe,SellMe)

#######################################################################################################
This topic was modified 3 years ago by gab.jornacion
 
Posted : 23/04/2021 1:03 pm
Mike
 Mike
(@vanguardai)
Posts: 70
Co-Founder Admin
 

can you post your script here so we can troubleshoot it?

 
Posted : 23/04/2021 2:14 pm
gab.jornacion
(@gab-jornacion)
Posts: 5
Active Member User
Topic starter
 

@vanguardai I edited the thread. The Attached file didn't upload I guess. anyway, the code is within the post now 😀

 
Posted : 23/04/2021 2:56 pm
Mike
 Mike
(@vanguardai)
Posts: 70
Co-Founder Admin
 

I checked and the script looks to be working as intended, in those times PHR had low volume so a buy signal won't trigger. Volume also refers to shares traded so it might vary per stock, you can change this into value by modifying the formula to (last * volume).

For the backtesting portion, my guess is that you don't have a big enough initial cash or the max amount per trade is too big. In the event you have a buy signal but not enough cash in the portfolio, you won't be able to execute that buy signal since we are trying to simulate live trading. You can also check the trade logs if that's the case.

I did a sample backtest against the PSEi and looks like it works fine and more importantly, performed better than the PSEi so congrats! ? 

1619162087-backtestsample.jpg
 
Posted : 23/04/2021 3:14 pm
Mike
 Mike
(@vanguardai)
Posts: 70
Co-Founder Admin
 

The version below includes MACD crossover as part of the buy signal.

//File name: STS_kgj_position.ts
//Developer: Gabster
//Date created: 20210422
//Script description:
// Script for Short Term
// Below are the conditions need to fulfill for short term buy/sell signals
#######################################################################################################
#1) Green Candle
#2) Green Volume - Above 5M pesos
#3) Above MA20
#5) MACD crosses above its signal line ? Bullish confirmation need to be patterned with MA20
#6) At Support
#######################################################################################################

#Set MA20 and Plot Line
Set ma20 = sma(close,20)
plot(ma20,line,red,main)

#Set MACD
Set MACD_line = MACD(12,26,9, exponential)
Set MACD_signal = MACDSIGNAL(12,26,9, exponential)
Set Hist = MACD_line - MACD_signal
//Plot MACD
Set MACDhistup = if(hist > 0, hist ,0)
Set MACDhistdown = if(hist < 0, hist, 0)
plot(MACDhistup, stackedbar, green, MACD)
plot(MACDhistdown, stackedbar, red, MACD)
plot( MACD_line, line, any, MACD)
plot(MACD_signal, line, any, MACD)

#Set Candle Status
Set IsGreen = Close > Open
Set IsRed = Close < Open

#Check green volume
SET isVolumeGreen = (close*VOLUME) > 5000000 AND isGreen
Set isVolumeRedWith5M = (close*VOLUME) > 5000000 AND isRed

#Check if Candle is Above MA20
Set isAboveMA20 = LAST > ma20
Set isBelowMA20 = LAST <ma20

#Breakout

Set Breakhigh = max(high,1)
Set Breaklow = min(low,1)
Set Breakoutsignal = close > ref(breakhigh,1)
Set Breakdownsignal = close < ref(breaklow,1)

#plot(breakhigh,step,green,main)
#plot(breaklow,step,red,main)

Set BuyMe = isGreen AND isVolumeGreen AND isAboveMA20 and Breakoutsignal and crossover(MACD_Line, MACD_Signal)
Set SellMe = isRed AND isBelowMA20

#PlotSignals
plotbuysell(BuyMe,SellMe, Green, Red, Main)
#plot(SellMe, Sell, Green, Main)

signals(BuyMe,SellMe)

#######################################################################################################

1619162853-with-macd.png
 
Posted : 23/04/2021 3:27 pm
gab.jornacion
(@gab-jornacion)
Posts: 5
Active Member User
Topic starter
 

@vanguardai So i'm kinda overthinking this huh? haha Thank you for the feedback and adding MACD as part of the buy signal! 😀

 
Posted : 23/04/2021 7:53 pm
Share: