Description
PLEASE DO NOT USE THIS CBOT YET!!
I am building a very simple grid trading system.
there is still a lot work to it, so im sharing it here in order to make a community development.
Please feel free to give ideas, backtest, improve - what you wish! :)
Currently i named it
//+------------------------------------------------------------------+
//| Classic GRID |
//| v0.1 05022018 |
//| Community Developement |
//+------------------------------------------------------------------+
please just share your improvements and follow the version sequence with date, in order to keep it organized! ;)
//+------------------------------------------------------------------+
//| Classic GRID |
//| v0.1 05022018 |
//| Community Developement |
//+------------------------------------------------------------------+
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.Threading;
using cAlgo.API.Requests;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class GRID : Robot
{
[Parameter("Volume", DefaultValue = 1000)]
public int Volume { get; set; }
[Parameter("Magic", DefaultValue = "GRID")]
public string _Magic { get; set; }
[Parameter("Gridstep", DefaultValue = 3)]
public int Gridstep { get; set; }
//ideas
// [Parameter("ATR_period", DefaultValue = 14)]
// public int _ATR_period { get; set; }
// [Parameter("Lot_Multiplier", DefaultValue = 1)]
// public int _Lot_Multiplier { get; set; }
private double spread;
private double mean;
private double limits;
private double Gridstep2;
private double limits_buy;
private double limits_sell;
private double b3;
private double b2;
private double b;
private double s;
private double s2;
private double s3;
protected override void OnStart()
{
limits = (Gridstep * 2);
spread = (Symbol.Ask - Symbol.Bid) / Symbol.PipSize;
mean = Symbol.Bid + ((Symbol.Ask - Symbol.Bid) / 2);
limits_buy = mean + (limits * Symbol.PipSize);
limits_sell = mean + (limits * Symbol.PipSize);
Gridstep2 = Gridstep * Symbol.PipSize;
b = limits_buy - Gridstep2;
s = limits_sell + Gridstep2;
Print("mean: " + mean);
Print("level: " + b);
Print("target: " + limits_buy);
Print("spread: " + spread);
Print("Bid: " + Symbol.Bid);
Print("Ask: " + Symbol.Ask);
}
protected override void OnTick()
{
}
protected override void OnBar()
{
limits = (Gridstep * 4);
spread = (Symbol.Ask - Symbol.Bid) / Symbol.PipSize;
mean = Symbol.Bid + ((Symbol.Ask - Symbol.Bid) / 2);
limits_buy = mean + (limits * Symbol.PipSize);
limits_sell = mean - (limits * Symbol.PipSize);
Gridstep2 = Gridstep * Symbol.PipSize;
b = limits_buy - Gridstep2;
b2 = limits_buy - Gridstep2 * 2;
b3 = limits_buy - Gridstep2 * 3;
s = limits_sell + Gridstep2;
s2 = limits_sell + Gridstep2 * 2;
s3 = limits_sell + Gridstep2 * 3;
//b
PlaceStopOrder(TradeType.Buy, Symbol, Volume, b, _Magic, Gridstep * 7, Gridstep, null, "b");
//b2
PlaceStopOrder(TradeType.Buy, Symbol, Volume, b2, _Magic, Gridstep * 6, Gridstep * 2, null, "b2");
//b3
PlaceStopOrder(TradeType.Buy, Symbol, Volume, b3, _Magic, Gridstep * 5, Gridstep * 3, null, "b3");
//s
PlaceStopOrder(TradeType.Sell, Symbol, Volume, s, _Magic, Gridstep * 7, Gridstep, null, "s");
//s2
PlaceStopOrder(TradeType.Sell, Symbol, Volume, s2, _Magic, Gridstep * 6, Gridstep * 2, null, "s2");
//s3
PlaceStopOrder(TradeType.Sell, Symbol, Volume, s3, _Magic, Gridstep * 5, Gridstep * 3, null, "s3");
Print("mean: " + mean);
Print("level: " + b);
Print("target: " + limits_buy);
Print("spread: " + spread);
Print("Bid: " + Symbol.Bid);
Print("Ask: " + Symbol.Ask);
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
// private void RCN()
// {
// ChartObjects.DrawText("pan", A_cmt_calc(), StaticPosition.TopLeft, Colors.Tomato);
// }
// private string A_cmt_calc()
// {
//
// string "\nATR" + ATR_value;
// string "\nATR" + ATR_long_value;
// }
}
}
CoreTradingHouse
Joined on 05.02.2018
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: GRID.algo
- Rating: 5
- Installs: 2260
- Modified: 13/10/2021 09:54
Comments
@CoreTradingHouse
In 2018, you started a simple grid system. Any update on your work?
Hi, Thank you for your work. It would be interesting to see a linear martingal like
- when you loose add : X lots.
- when you win decrease by : X lots.
I cannot code but I have many ideas. If you are interests thank you for let me know.
Hello Sir is there any news about this Robot ?