Hello,
first of all great Work, after testing some different bots i find this one the most advanced and especially the most user friendly bot.
Now i'm new to coding but i would like to get started with my own strategy could you give me some advice on how to do so?
For testing i would like to create a simple strategy that got 2 inputs
Sell At, Buy At
All it should do check the price of last buy and sell if "Sell At" = x% (where x is the difference between last buy and current price ) than reverse to sell and same procedure (check last sell price and buy if "But at"=-x%).
Some help would be well appreciated.
This should get you started - it buys at a specified price and sells at a different specified price:
// helpers
// var _ = require('lodash');
var log = require('../core/log.js');
var config = require('../core/util.js').getConfig();
var settings = config.buyatsellat;
// let's create our own method
var method = {};
// prepare everything our method needs
method.init = function() {
this.name = 'buyatsellat';
}
// What happens on every new candle?
method.update = function(candle) {
//log.debug('in update');
}
// for debugging purposes log the last
// calculated parameters.
method.log = function(candle) {
//log.debug(this)
}
method.check = function() {
if (this.candle.close > settings.sellat) {
this.advice('short');
log.debug("Issued Buy @ " + this.candle.close)
return;
}
if (this.candle.close < settings.buyat) {
this.advice('long');
log.debug("Issued Sell @ " + this.candle.close)
return;
}
}
module.exports = method;
Hi @mcowger, I've followed your instructions here but can't get the config working.
I've added this lines into my config.js file:
config.buyatsellat = {
parameters: {
sellat: 0.003,
buyat: 0.002
}
}
This values are for testing purposes.
When opening the backtest option and selecting this new strategy, it does not bring the default values.
Also, when using manual input, gekko cannot perform the back test properly.
Thanks!
@raffus Hi,
to achieve that you will have to add also a new file here:
config\strategies\buyatsellat.toml
@mcowger Thanks for you help!
As i understand from your code, this strategy buys at a specific price and sells at an other specific price right?
Can we add a percentage instead as i described in my first post?
Check the price of last buy and sell if "Sell At" = x% (where x is the difference between last buy and current price ) than reverse to sell and same procedure (check last sell price and buy if "But at"=-x%).
Important is that the % is calculated on the last buy or sell price.
As i understand there for we have to store something (last buy/sell price and calculate a percentage from the last buy/sell price and the current price. Than check if this percentage matched the input "Buy At" / Sell At" and advice right? )
Any suggestions how to code that?
hey @macd2,
i find this one the most advanced and especially the most unfriendly bot.
This is definitely an issue, if you are able to figure out how we make it (or the documentation) more friendly let us know :)
I've added this lines into my config.js file:
If you are using the UI (website) to select data and start a backtest you should completely ignore this config.js file. [EDIT] I see you figured it out:
to achieve that you will have to add also a new file here: configstrategies\buyatsellat.toml
How this works is: Gekko can only run backtests by consuming config files (like the sample-config.js), however if you use the UI the UI will construct this config file and pass that to a backtest. The UI bases different part of this config on TOML files (going through the UI so the user can change them dynamically).
As i understand there for we have to store something (last buy/sell price and calculate a percentage from the last buy/sell price and the current price. Than check if this percentage matched the input "Buy At" / Sell At" and advice right? )
Yes exactly. Here is a check function that does that (pseudo code, untested):
method.check = function(candle) {
// I guess these % are in your config
const buyat = 5; // amount of percentage of difference required
const sellat = 5; // amount of percentage of difference required
if(this.previousAction === "buy") {
// convert the 5% into 1.05 (we want the price to be 105% of the previous buy price).
const multiplier = (1 + buyat / 100);
// calculate the minimum price in order to sell
const threshold = previousActionPrice * multiplier;
// we sell if the price is more than the required threshold
if(candle.close > threshold) {
this.advice('sell');
this.previousAction = 'sell';
this.previousActionPrice = candle.close;
}
}
else if(this.previousAction === "sell") {
// same as above but reversed
}
}
Keep in mind that this strategy assumes the trader (real trader or paper trader) was able to execute close to market price, this is not always a fair assumption (think about slippage, spread and the fees you need to pay).
@askmike
i find this one the most advanced and especially the most unfriendly bot.
This is definitely an issue, if you are able to figure out how we make it (or the documentation) more friendly let us know :) I mean user friendly :D
awesome this looks like the thing i'm after i just did two changes
1.
// I guess these % are in your config
const buyat = settings.buyat // amount of percentage of difference required
const sellat = settings.sellat // amount of percentage of difference required
this means the setting is now pulled out of the .toml file right?
buyat= 5.0
sellat= 5.0
If i would like to add this to config i will have to add something like this right right?
config.buyatsellat = {
parameters: {
sellat: 5.00,
buyat: 5.002
}
}
Now for the paper trader to test if it works we need one more thing. The first action shell be buy at current price otherwise this will obviously not work since when you start gekko there was no previous buy or sell action?
Or even better can we store all previous buy and sell somewhere so that this strategy is always first checking if there was a previous buy or sell and if yes use this data if not buy once at current price.
Thanks a lot!
this means the setting is now pulled out of the .toml file right?
If you have the described toml file you also need to do this (assuming the toml file is called buyatsellat:
var config = require('../core/util.js').getConfig();
var settings = config.buyatsellat;
After that settings is an object with everything in the toml.
Now for the paper trader to test if it works we need one more thing. The first action shell be buy at current price otherwise this will obviously not work since when you start gekko there was no previous buy or sell action?
Yes. So in your init method you can do:
this.previousAction = 'sell';
this.previousActionPrice = 0;
Which is not true (there was no previous sell) but it will force your strategy into the the second if clause (which will trigger it to buy because the price is always higher than 5% above 0).
@askmike
thaks for your replay:
now i was testing your cod but unfortunately it somehow its not working:
i'm also struggling here:
else if(this.previousAction === "sell") {
// same as above but reversed
// convert the 5% into 0.95 (we want the price to be 95% of the previous sell price).
const multiplier = ( sellat / 100*?);
when i launch the paper trader its just doing noting no trades appear even if i tweak the values.
any idea?
Are you starting it with the backtest option? Are you sure the values will
trigger a sale?
On Fri, Jul 14, 2017 at 7:32 AM, macd2 notifications@github.com wrote:
@askmike https://github.com/askmike
thaks for your replay:
now i was testing your cod but unfortunately it somehow its not working:
i'm also struggling here:else if(this.previousAction === "sell") { // same as above but reversed //
convert the 5% into 0.95 (we want the price to be 95% of the previous sell
price). const multiplier = ( sellat / 100*?);
when i launch the paper trader its just doing noting no trades appear even
if i tweak the values.any idea?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/askmike/gekko/issues/844#issuecomment-315374761, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AB1xTE6eba8f9eXaGC9VO8i11gshraDEks5sN3v3gaJpZM4OXYMn
.
--
-- Matt
@mcowger i'm starting via the UI and yes it should be at least one trade as explained by Mike earlier on.
@askmike Hey Mike would be great if you could just take a sec and let me know how to get this thing to work.
Thanks
when i launch the paper trader its just doing noting no trades appear even if i tweak the values.
any idea?
yes: log the values via console.log, that way you can see what the values are and why they are not hit.
@askmike Thanks for your replay. After some changes i get this:
\gekko-stablestrategiesbuyatsellat.js:67 const threshold = previousActionPrice * multiplier;
ReferenceError: previousActionPrice is not defined
at Base.method.check (\gekko-stablestrategiesbuyatsellat.js:67:43)
at Base.bound (\gekko-stablenode_modules\lodash\dist\lodash.js:729:21)
at Base.propogateTick (\gekko-stable\plugins\tradingAdvisor\baseTradingMethod.js:227:10)
at Base.bound [as propogateTick] (\gekko-stablenode_modules\lodash\dist\lodash.js:729:21)
at Base.tick (\gekko-stable\plugins\tradingAdvisor\baseTradingMethod.js:163:10)
at Base.bound [as tick] (\gekko-stablenode_modules\lodash\dist\lodash.js:729:21)
at Actor.processCustomCandle (\gekko-stable\plugins\tradingAdvisor\tradingAdvisor.js:75:15)
at CandleBatcher.bound (\gekko-stablenode_modules\lodash\dist\lodash.js:729:21)
at emitOne (events.js:96:13)
at CandleBatcher.emit (events.js:188:7)
The .js file looks like this
else if(this.previousAction === "sell") {
// same as above but reversed
// use input as value
const multiplier = (sellat);
// calculate the minimum price in order to buy
const threshold = previousActionPrice * multiplier;
// we buy if the price is more than the required threshold
if(candle.close < threshold) {
this.advice('buy');
this.previousAction = 'buy';
this.previousActionPrice = candle.close;
}
I also did the backtest with an other strategy there it just works fine.
const threshold = previousActionPrice * multiplier;
needs to be
const threshold = this.previousActionPrice * multiplier;
@askmike ok great now the node gekko --config config.js --backtest runs with no errors but still there are no trades happening, i guess the problem is somewhere in this.previousActionPrice;
because when i change "this.previousActionPrice" in the method.init
from:
this.previousActionPrice = 0;
to
this.previousActionPrice = 0.00001;
i get the following error:
C:\gekko-stable\plugins\paperTraderlogger.js:71
var at = trade.date.format('YYYY-MM-DD HH:mm:ss');
TypeError: Cannot read property 'format' of undefined
at Logger.handleTrade (C:\gekko-stable\plugins\paperTraderlogger.js:71:24)
at PaperTrader.processAdvice (C:\gekko-stable\plugins\paperTrader\paperTrader.js:153:16)
at Actor.bound (C:\gekko-stablenode_modules\lodash\dist\lodash.js:729:21)
at emitOne (events.js:96:13)
at Actor.emit (events.js:188:7)
at Actor.bound [as emit] (C:\gekko-stablenode_modules\lodash\dist\lodash.js:729:21)
at Actor.relayAdvice (C:\gekko-stable\plugins\tradingAdvisor\tradingAdvisor.js:85:8)
at Base.bound (C:\gekko-stablenode_modules\lodash\dist\lodash.js:729:21)
at emitOne (events.js:96:13)
at Base.emit (events.js:188:7)
i simplified the code for testing a bit and it looks like this now:
```javascript
// prepare everything our method needs
method.init = function() {
this.name = 'buyatsellat';
this.previousAction = 'sell';
this.previousActionPrice = 0.00001;
}
// What happens on every new candle?
method.update = function(candle) {
//log.debug('in update');
}
// for debugging purposes log the last
// calculated parameters.
method.log = function(candle) {
}
method.check = function(candle) {
// I guess these % are in your config
const buyat = 1.05; // amount of percentage of difference required
const sellat = 0.95; // amount of percentage of difference required
if(this.previousAction === "buy") {
// use input as value
//const multiplier = (sellat);
// calculate the minimum price in order to sell
const threshold = this.previousActionPrice * buyat;
// we sell if the price is more than the required threshold
if(candle.close > threshold) {
this.advice('sell');
this.previousAction = 'sell';
this.previousActionPrice = candle.close;
}
}
else if(this.previousAction === "sell") {
// same as above but reversed
// use input as value
//const multiplier = (buyat);
// calculate the minimum price in order to buy
const threshold = this.previousActionPrice * sellat;
// we buy if the price is less than the required threshold
if(candle.close < threshold) {
this.advice('buy');
this.previousAction = 'buy';
this.previousActionPrice = candle.close;
}
}
}
module.exports = method;
We're getting to the point were you have a good understanding of what Gekko can do for you but you run into javascript errors in your strat. Gekko is a tool that allows you to automate certain things, but in order to do so you are expected to write your strats in javascript. I cannot go helping you write your first javascript for much longer, this is an issue tracker to discuss bugs and features for gekko.
If you take a close look at the error you see it complains about this exact line:
var at = trade.date.format('YYYY-MM-DD HH:mm:ss');
Which you did not copy, so it's hard to see what the part of the code is trying to do. If you don't do anything with the at variable you can just delete this line.
but still there are no trades happening
Your script is responsible for calling out signals, if this is not happening your if checks are never passing, in order to debug this you can use console.log to check the different variables that are calculated for each candle.
EDIT: by a closer look it looks like the error is coming from Gekko itself, can you let me know over what market you were trying to backtest? I'll try to reproduce the error and figure out what is wrong.
@askmike yes you absolutely right i'm not a coder i just try to research and get this thing to work as good as i can. But it's just not working, this is frustrating so who else can i ask than the creator of gekko himself?
All i need is one version of this strategy that works to understand how to make better strategies in the future.
Of cause i understand it is not your job to write costume stuff for users but maybe you could do an exception in this case I'm sure it would take you not more than a few minutes to get this to work, for me it would be days if not longer.
So when you have some spare time i would greatly appreciate if you could do a quick evaluation and tell me what to do in order to get this strategy to work. This is what i got so far:
Config.js:
config.tradingAdvisor = {
enabled: true,
method: 'buyatsellat',
candleSize: 1,
historySize: 3,
adapter: 'sqlite',
talib: {
enabled: false,
version: '1.0.2'
buyatsellat.js
```javascript
// helpers
// var _ = require('lodash');
var log = require('../core/log.js');
//var config = require('../core/util.js').getConfig();
//var settings = config.buyatsellat;
// let's create our own method
var method = {};
// prepare everything our method needs
method.init = function() {
this.name = 'buyatsellat';
this.previousAction = 'sell';
this.previousActionPrice = 0;
}
// What happens on every new candle?
method.update = function(candle) {
//log.debug('in update');
}
// for debugging purposes log the last
// calculated parameters.
method.log = function(candle) {
//log.debug(this.previousAction)
}
method.check = function(candle) {
const buyat = 1.05; // amount of percentage of difference required
const sellat = 0.95; // amount of percentage of difference required
if(this.previousAction === "buy") {
// calculate the minimum price in order to sell
const threshold = this.previousActionPrice * buyat;
// we sell if the price is more than the required threshold
if(candle.close > threshold) {
this.advice('sell');
this.previousAction = 'sell';
this.previousActionPrice = candle.close;
}
}
else if(this.previousAction === "sell") {
// calculate the minimum price in order to buy
const threshold = this.previousActionPrice * sellat;
// we buy if the price is less than the required threshold
if(candle.close < threshold) {
this.advice('buy');
this.previousAction = 'buy';
this.previousActionPrice = candle.close;
}
}
}
module.exports = method;
Honestly - in order to make this tool work....you'll need to be or become a
coder.....theres no way around it.
On Thu, Jul 20, 2017 at 1:13 AM, macd2 notifications@github.com wrote:
@askmike https://github.com/askmike yes you absolutely right i'm not a
coder i just try to research and get this thing to work as good as i can.
But it's just not working, this is frustrating so who else can i ask than
the creator of gekko himself?All i need is one version of this strategy that works to understand how to
make better strategies in the future.
Of cause i understand it is not your job to write costume stuff for users
but maybe you could do an exception in this case I'm sure it would take you
not more than a few minutes to get this to work, for me it would be days if
not longer.So when you have some spare time i would greatly appreciate if you could
do a quick evaluation and tell me what to do in order to get this strategy
to work. This is what i got so far:
Config.js:
config.tradingAdvisor = { enabled: true, method: 'buyatsellat',
candleSize: 1, historySize: 3, adapter: 'sqlite', talib: { enabled: false,
version: '1.0.2'buyatsellat.js
// helpers// var _ = require('lodash');var log = require('../core/log.js');
//var config = require('../core/util.js').getConfig();//var settings = config.buyatsellat;
// let's create our own methodvar method = {};
// prepare everything our method needs
method.init = function() {
this.name = 'buyatsellat';this.previousAction = 'sell'; this.previousActionPrice = 0;}
// What happens on every new candle?method.update = function(candle) {
//log.debug('in update');
}
// for debugging purposes log the last // calculated parameters.method.log = function(candle) {
//log.debug(this.previousAction)
}
method.check = function(candle) {
const buyat = 1.05; // amount of percentage of difference required
const sellat = 0.95; // amount of percentage of difference requiredif(this.previousAction === "buy") {
// calculate the minimum price in order to sell
const threshold = this.previousActionPrice * buyat;// we sell if the price is more than the required threshold if(candle.close > threshold) { this.advice('sell'); this.previousAction = 'sell'; this.previousActionPrice = candle.close; }}
else if(this.previousAction === "sell") {
// calculate the minimum price in order to buy
const threshold = this.previousActionPrice * sellat;// we buy if the price is less than the required threshold if(candle.close < threshold) { this.advice('buy'); this.previousAction = 'buy'; this.previousActionPrice = candle.close; }}
}
module.exports = method;—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/askmike/gekko/issues/844#issuecomment-316630622, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AB1xTPvYs_MX2aAw2Tx1cIqw_OH0t_-_ks5sPwwrgaJpZM4OXYMn
.
--
-- Matt
@mcowger yes this is a common pain point. The major thing is that Gekko doesn't come with any complex strategies, so in order to effectively use gekko you need a way to "tell" Gekko a "strategy" and I don't know an easy way to do this without programming. I am very open to discussions for this, but at the end of the day Gekko is meant as a "tool" people can use to run their own strats, not end to end solution.
Maybe a platform like tradewave (scroll down to "Introducing the world's simplest trading strategy editor. No coding required.") would be handier for non programmers: https://tradewave.net/features [this is not an endorsement for tradewave].
i think that gekko has the potential to become much more than only a tool for "nerds".
If there would be at least some more tutorials or at least a "structure" how to build a strat, something like a pre build set of rules one could work with.
But like this it is very difficult for none coders to really use the power and all the work that already has been devoted to Gekko.
Is there nobody out there who could please review the strategy and make it work not only for me but also for all the other none coders?
I will look into your specific problem asap. And you are very right, I want
gekko to become more, but who has the time?
On 21 Jul 2017 17:53, "macd2" notifications@github.com wrote:
i think that gekko has the potential to become much more than only a tool
for "nerds".
If there would be at least some more tutorials or at least a "structure"
how to build a strat, something like a pre build set of rules one could
work with.But like this it is very difficult for none coders to really use the power
and all the work that already has been devoted to Gekko.Is there nobody out there who could please review the strategy and make it
work not only for me but also for all the other none coders?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/askmike/gekko/issues/844#issuecomment-317054129, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AA7MD1UJ5nLuDjU3OPD2h9wPCIh-CN3cks5sQNeVgaJpZM4OXYMn
.
Hi @macd2... As far as I can understand you just want a strategy that buys and sells the specific asset/currency. Is that right? if so, you already have something ready here.
Of cause i understand it is not your job to write costume stuff for users but maybe you could do an exception in this case I'm sure it would take you not more than a few minutes to get this to work, for me it would be days if not longer.
As far as I can see, @mcowger has already done the job for you. This strategy buys and sells it at a specific price. Whats going on there? Whats the problem?
I'm not sure what else do you expect from the folks here when you ask us to write you a new strategy. There's nothing we can do to put this technic into your head, but with some time and dedication I'm 100% positive you'll learn how to build your own strategy and even more, maybe use this recently learned knowledge to share your experiences with the community.
I'd strongly suggest you to take some time and dedicate your attention trying to understand programing logic. Thats the only way you'll archive your goal here. Don't give up or you'll be leaded to failure. If you really want to use gekko to make some profit you should be more dedicated and persistent.
After taking some weeks reading about gekko and trying to figure out how it works, I'll try to help to improve the documentation so it might be easier for people to understand how to build a strategy. If you want some examples, take a loot at the other built-in strategies. Thats a nice way to start: read some different code and make some clue about how this works.
Wish you luck buddy.
BR,
R
Hi @raffus,
Thanks for your replay!
Hi @macd2... As far as I can understand you just want a strategy that buys and sells the specific asset/currency. Is that right? if so, you already have something ready here.
No this is not exactly right, my goal was:
Check the price of last buy and sell if "Sellat" = x% (where x is the difference between last buy and current price ) than reverse to sell and same procedure (check last sell price and buy if "buyat"=x%).
Important is that the % is calculated on the last buy or sell price.
As far as I can see, @mcowger has already done the job for you. This strategy buys and sells it at a specific price. Whats going on there? Whats the problem?
Did you tested the code yourself?
It is not working some how there are no trades occurring. I made the code as simple as i could (no .toml file no fancy stuff), i tweaked the settings, the values the .config file but still the same result no trades.
This is the issue i have.
@macd2 I am getting the same error. I tried making some changes in logging functionality, but I don't have much knowledge about coding, so gave up after some time.
Interestingly, you strategy can be configured in Zenbot, which is kinda rival of Gekko. I tried in it, and got good results for BTC-USD on gdax over 14 days period.
@pushkarnagle hey this is interessting :D
Did you just copied the start and used it as it is or you modified it?
@macd2 I just checked your strategy:
The only two problems I see (regarding the "no trades happening") are:
Here is a gist of my updated version: https://gist.github.com/askmike/3d7fdca529a287e42219f4ee7c89a1a3
And here are backtest results:

(as you can see after a point it waits for the price to go down, which has not happened)
@askmike awesome thanks a lot!
@macd2 No, I changed the parameters and then tried.
@askmike Great stuff! We should add stop loss percentage also, just in case the market trends downwards.
_Sent from my Motorola XT1706 using FastHub_
We should add stop loss percentage also, just in case the market trends downwards.
Yes, so in Gekko you can extend your strategy to implement a stoploss: this strategy already has information what the latest buy and sell was, so you can easily check if the price swings the wrong way to hard to get out of your position.
@pushkarnagle you probably want to change
candle.close == stop_loss
to:
candle.close < stop_loss
since the changes of the numbers being 100% the same are very slim.
I think this code should work for Stop Loss order.
// helpers
// var _ = require('lodash');
var log = require('../core/log.js');
//var config = require('../core/util.js').getConfig();
//var settings = config.buyatsellat;
// let's create our own method
var method = {};
// prepare everything our method needs
method.init = function() {
this.name = 'buyatsellat';
this.previousAction = 'sell';
this.previousActionPrice = Infinity;
}
// What happens on every new candle?
method.update = function(candle) {
//log.debug('in update');
}
// for debugging purposes log the last
// calculated parameters.
method.log = function(candle) {
//log.debug(this.previousAction)
}
method.check = function(candle) {
const buyat = 1.05; // amount of percentage of difference required
const sellat = 0.97; // amount of percentage of difference required
const stop_loss_pct = 0.95; // amount of stop loss percentage
if(this.previousAction === "buy") {
// calculate the minimum price in order to sell
const threshold = this.previousActionPrice * buyat;
// calculate the stop loss price in order to sell
const stop_loss = this.previousActionPrice * stop_loss_pct;
// we sell if the price is more than the required threshold or equals stop loss threshold
if(candle.close > threshold || candle.close == stop_loss) {
this.advice('short');
this.previousAction = 'sell';
this.previousActionPrice = candle.close;
}
}
else if(this.previousAction === "sell") {
// calculate the minimum price in order to buy
const threshold = this.previousActionPrice * sellat;
// we buy if the price is less than the required threshold
if(candle.close < threshold) {
this.advice('long');
this.previousAction = 'buy';
this.previousActionPrice = candle.close;
}
}
}
module.exports = method;
@pushkarnagle yes great exactly this was what i was trying to add as well!
@macd2 Can you please test on the market which had gone down? I have data of the markets which is going up continuously, so I couldn't test whether Stop Loss is actually working or not.
@pushkarnagle i did and it is actually not.
It does not effect the chart on an downtrend. I tried different values but there is no sell in a downtrend more than 5% as you codes tells const stop_loss_pct = 0.95;
@macd2 Yes, I know. Must be something wrong in OR condition.
@macd2 and @pushkarnagle see my previous comment.
@askmike Thanks for the tip! Its working now.
@macd2 I have added one new parameter, sellat_up, which will buy again if the market goes up from the last sell price. This is to ensure multiple buy trades, which will activate stop loss.
Here is corrected code:
// helpers
// var _ = require('lodash');
var log = require('../core/log.js');
//var config = require('../core/util.js').getConfig();
//var settings = config.buyatsellat;
// let's create our own method
var method = {};
// prepare everything our method needs
method.init = function() {
this.name = 'buyatsellat';
this.previousAction = 'sell';
this.previousActionPrice = 1200;
}
// What happens on every new candle?
method.update = function(candle) {
//log.debug('in update');
}
// for debugging purposes log the last
// calculated parameters.
method.log = function(candle) {
//log.debug(this.previousAction)
}
method.check = function(candle) {
const buyat = 1.05; // amount of percentage of difference required
const sellat = 0.97; // amount of percentage of difference required
const stop_loss_pct = 0.95; // amount of stop loss percentage
const sellat_up = 1.01; // amount of percentage from last buy if market goes up
if(this.previousAction === "buy") {
// calculate the minimum price in order to sell
const threshold = this.previousActionPrice * buyat;
// calculate the stop loss price in order to sell
const stop_loss = this.previousActionPrice * stop_loss_pct;
// we sell if the price is more than the required threshold or equals stop loss threshold
if((candle.close > threshold) || (candle.close < stop_loss)) {
this.advice('short');
this.previousAction = 'sell';
this.previousActionPrice = candle.close;
}
}
else if(this.previousAction === "sell") {
// calculate the minimum price in order to buy
const threshold = this.previousActionPrice * sellat;
// calculate the price at which we should buy again if market goes up
const sellat_up_price = this.previousActionPrice * sellat_up;
// we buy if the price is less than the required threshold or greater than Market Up threshold
if((candle.close < threshold) || (candle.close > sellat_up_price)) {
this.advice('long');
this.previousAction = 'buy';
this.previousActionPrice = candle.close;
}
}
}
module.exports = method;
And backtest results:

Great! So keep in mind that even though the profit is 50% (based on paperTrader settings which should reflect your fees and slippage), the price of bitcoin went up by 96%. So you would have been better off buying and holding (from a profit point, not from a risk perspective).
Yes, you are right. In my opinion, 90% of the portfolio should be 'wait and watch' strategy. One can put his 10% in such tradebot for instant profits. I am planning to do the same. Just waiting for my Raspberry Pi to be delivered.
@askmike we getting there :)
I'm still working on a solution for this up and down trend problem and improving this strat is there a way to get the value of the last Candle that was recorded at the market (last market price).
At the moment it is this.previousActionPrice = candle.close; which is only the price of the last action performed by the Strat I would like to use market data and get value of last 1 min candle for example: var marketPrice = this.LastPrice is that possible?
EDIT: Never mind got it, its simply candle.close
@pushkarnagle hello,
I'm setting up a strategie based on above code but merged with DEMA indicators.
I just spent 20mn to confuse myself about the use of buyat and sellat const in your formulas above which are inverted :) I mean, the values of the variables have sense, not the comment nor the name of the variable.
Did you really mean it this way ?
Thanks, I just don't want to miss something.
Yetz
Why...becktest not working script
@Yetzira
Hi,
I am also just starting to look into Gekko and trading strategies. This one looks like it could be a starting point.
Would you mind sharing what you implemented ? :)
Thanks Jabbaxx
@Yetzira what you don't understand?
can you post an example?
Hi, just stumbled on this thread. It is wonderful. I am new and playing around with the strategies. Just noted a problem that with backtesting if the market is going down then the stop-loss is not working. I am using the last (corrected) code provided above. Did anyone solved it? Response will be appreciated.
Thanks
nutepi
Most helpful comment
I will look into your specific problem asap. And you are very right, I want
gekko to become more, but who has the time?
On 21 Jul 2017 17:53, "macd2" notifications@github.com wrote: