Evaluation Discussion

Welcome to this discussion thread. Feel free to ask questions or discuss things related to this section.

1 Like

Does anybody have an idea on how to use an external database? For example using the number of google-searches per day. I know…not a great idea, but just to learn more how to use Pine Editor

The last I checked it was not possible with external api calls. You would have to work with your own script like Ivan is showing you at the end of the course.

1 Like

Hi filip,

Really enjoying the course so far! I have a question though forgive me if I missed this in the course. When I change time frames I get radically different results in terms of profits and losses for the same strategy I have added to the chart. Is there a way to set your strategy to a 1 hour ,4 hour or daily candles through pinescript?

thanks again for the knowledge

FJ

Yes, but that’s completely normal. If you switch timeframe, then all values will be different. Prices will be different, moving averages different, everything will be different since the candles are different.

You can use the security function to create a variable that holds data for a specific security with a specific timeframe. But this is usually only necessary if you want to work with multiple timeframes at once. Otherwise you should simply choose the timeframe in the chart.

Here is info about the function I’m talking about. https://www.tradingview.com/study-script-reference/#fun_security. And a video if that helps: https://www.youtube.com/watch?v=K60Jc5WXsH4

Thank you for replying to me Filip!

1 Like

Hey,

Have you tried this with real money?

I was wondering how accurate this is compared to real life trading. Do you have any servers or services you recommend for going live?

It would be nice to have a setup so that everything does not shut down if my computer crashes, goes to sleep, shuts down etc.

My results are based on daily chart, would you do a strategy that performs well on higher time frames and not good on lower time frames, or find a strategy that works well on all time frames?

Thanks!

1 Like

It’s always very hard to know. Usually you need to test the algo in real life as well. That’s for multiple reasons. When you simulate your trades, tradingview will interpret the history of the chart in the most favorable way possible when executing your trades. In reality, it might differ.

Also, you don’t really know if you have over-fitted your algo until you try it in real life.

Tradingview has a few brokers that they support, for example poloniex. If you are able to, I would suggest you try one of them.

Allright, thanks man!

1 Like

30 profit factor? The most I’ve done with tweaking this algo. is 6. Did you make any other major changes? I’m not sure if I’m doing something wrong.

Trading Algorithm Version 2.0

I just wanted to post my version of our test trading algorithm with the latest changes:

  • Adding max_risk parameter for risk management
  • Adding and tweaking a stoploss parameter for exiting the strategy
  • Adapting the size of the orders to size = max_risk / stoploss
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © andreashansch

//@version=3
strategy(title="Moving Average Crossing", overlay=true, initial_capital=2000, commission_type=strategy.commission.percent, commission_value=0.2)

//DATE AND TIME 
fromDay   = input(defval=1, title = "From day", minval=1)
fromMonth = input(defval=1, title = "From month", minval=1)
fromYear  = input(defval=2019, title = "From year", minval=2019)

toDay   = input(defval=18, title = "To day", minval=1)
toMonth = input(defval=4, title = "To month", minval=1)
toYear  = input(defval=2020, title = "To year", minval=2019)

//DEFINITIONS
shortMa  = sma(close, 49)
longMa   = sma(close, 81)
max_risk = strategy.equity * 0.01
stoploss = 295
size     = max_risk / stoploss

//LOGIC
timeInRange = (time > timestamp(fromYear, fromMonth, fromDay, 00, 00)) and (time < timestamp(toYear, toMonth, toDay, 23, 59))
longSignal  = crossover(shortMa, longMa)
shortSignal = crossover(longMa, shortMa)

//POSITIONS
strategy.entry(id="longPosition", long=true, qty=size, when=longSignal and timeInRange)
strategy.entry(id="shortPosition", long=false, qty=size, when=shortSignal and timeInRange)

strategy.exit("Exit Long", from_entry = "longPosition", loss = stoploss * 100)
strategy.exit("Exit Short", from_entry = "shortPosition", loss = stoploss * 100)

Hi @filip ! I’m getting the same results with and without the stoploss code at the end, don’t know what I’m missing, can you help me out?

//@version=4
strategy(title="MyFirstStrategy", overlay=true, initial_capital=2000, commission_type=strategy.commission.percent, commission_value=0.2)

//DATE AND TIME
fromMonth = input(defval=1, title = "From month", minval=1)
fromDay = input(defval=1, title = "From day", minval=1)
fromYear = input(defval=2020, title = "From year", minval=2012)

toMonth = input(defval=5, title = "To month", minval=1)
toDay = input(defval=30, title = "To day", minval=1)
toYear = input(defval=2020, title = "To year", minval=2012)

//DEFINITIONS
longMa = sma(close, 28)
shortMa = sma(close, 50)

blue = ema(close, 8)
green = ema(close, 13)
yellow = ema(close, 21)
red = ema (close, 55)

r = rsi(close, 14)

max_risk = strategy.equity * 0.01
stoploss = 100
size = max_risk/stoploss

//LOGIC
timeInRange = (time > timestamp(fromYear, fromMonth, fromDay, 00, 00)) and (time < timestamp(toYear, toMonth, toDay, 23,59))
longSignal = crossover(blue, green) and timeInRange
shortSignal = crossover(red, blue) and timeInRange

//POSITIONS
strategy.entry(id="longPosition", long=true, qty=size, when=longSignal)
strategy.entry(id="shortPosition", long=false, qty=size, when=shortSignal)

strategy.exit("Exit long", from_entry = "longPosition", loss = stoploss*100)
strategy.exit("Exit short", from_entry = "shortPosition", loss = stoploss*100)

These are the results I’m getting from January 2020 - now, thanks in advance!