Long/short after a period of time.
#1
Hi everyone. I was searching for a couple of days now, and I can't find a solution to this. Basically I want to make a trade after a specified amount of time has passed from the last trade. I'm new to this bot, so sorry for any noobish behavior :) How should Ii approach this? I'm also trying to find documentation of the functions etc. in gekko . Something more detailed than the one found on gekko's page. Not a lot of material to learn from (yet?). Any advice in the matter will be appreciated. Right now I'm testing a strategy based on EMA's, which work good or bad depending on market conditions and simply swapping "long" ans "short" orders with each other inside the code. In moderate volatility for example works good, and gets hefty losses during high volatility and vice versa. Tried stop losses, but they really do more bad than good to the strategy making it erratic and unpredictable. Noticed that the few big losing positions last much much longer than the winning ones, so I thought if I was able to make a position last no longer than say 12 hours it might act as a stop loss in this case. Thank you in advance for any help.
  Reply
#2
Did you see this video?

https://youtu.be/6-74ZhrG0BE

Quote:Basically I want to make a trade after a specified amount of time has passed from the last trade.

Inside your check function you want to register the time (the candle time, this way your strategy will also work in backtests) you do an advice. And every following check you want to see if you did a trade x time ago, and if so do another one.
  Reply
#3
(10-08-2018, 06:22 AM)askmike Wrote: Inside your check function you want to register the time (the candle time, this way your strategy will also work in backtests) you do an advice. And every following check you want to see if you did a trade x time ago, and if so do another one.

I'm trying to register the time of a long trade by assigning it to a variable, but that value is changing every time conditions for 'long' are met.


for eg.

if(macd2 > macdSignal2 && macd2 < 0) {
        this.advice('long');
        var timesig = candle.start.format('D');
        
    }

I need to keep timesig at the time of the first trade and prevent it from changing every time it wants to take a long position, which it can't because it's already long.
Can I determine if this long trade already happened before?
  Reply
#4
Quote:I need to keep timesig at the time of the first trade and prevent it from changing every time it wants to take a long position, which it can't because it's already long.
Can I determine if this long trade already happened before?

The first thing: you say "var timesig = candle.start.format('D');", you probably want to create a variable once and set it's value. If you are fine with knowing whether you signaled a "long" before you need to track that as well, you have a few options:

- you can set the timesig to something like false after you signal a short, now you can simply check if this value is not false, if it is not that means you signaled previously.
- you can track the current advice, have a look at the example strategies because most do that. After that simply check if the current advice is not long before you set that.
- you can track it in another boolean.

Note that question has little to do with Gekko and more with javascript. I suggest familiarizing yourself with javascript.
  Reply


Forum Jump:


Users browsing this thread: