GR
Topics
07 Jan 2023, 14:45
710
5
07 Dec 2022, 10:59
487
1
Replies
gregory.bayard
09 Jan 2023, 14:44
RE:
PanagiotisChar said:
Hi there,
I don't think anybody will do this for free :) If you are looking for an expert to convert it, have a look at Consultants.
Need help? Join us on Telegram
Need premium support? Trade with us
ok, thx ! I improvised it myself, with what I found, it seems correct but I do not understand the backtest that gives me results out of condition. would I have made mistakes?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.GMTStandardTime, AccessRights = AccessRights.None)]
public class Roboteurusd : Robot
{
[Parameter(DefaultValue = "Robotichi", Group = "Label")]
public string MyLabel { get; set; }
[Parameter("Initial Quantity (Lots)", Group = "Volume", DefaultValue = 10000, MinValue = 0.01, Step = 0.01)]
public double InitialQuantity { get; set; }
[Parameter(Group = "Ichimoku", DefaultValue = 9)]
public int periodFast { get; set; }
[Parameter(Group = "Ichimoku",DefaultValue = 26)]
public int periodMedium { get; set; }
[Parameter(Group = "Ichimoku",DefaultValue = 52)]
public int periodSlow { get; set; }
[Parameter("Stop Loss",Group = "Protection", DefaultValue = 65)]
public int StopLoss { get; set; }
[Parameter("Take Profit",Group = "Protection", DefaultValue = 20)]
public int TakeProfit { get; set; }
[Parameter("MA Type", Group = "Moyenne Mobile")]
public MovingAverageType MAType { get; set; }
[Parameter("Source", Group = "Moyenne Mobile")]
public DataSeries SourceSeries { get; set; }
[Parameter("Moyenne Mobile", Group = "Moyenne Mobile", DefaultValue = 400)]
public int MaPeriods { get; set; }
[Parameter("Begin Trading Hour",Group = "Horaire", DefaultValue = 9.0)]
public double Begin { get; set; }
[Parameter("Ending Trading Hour",Group = "Horaire", DefaultValue = 11.0)]
public double Ending { get; set; }
[Parameter("Trailing Stop", Group = "Trailing Stop", DefaultValue = false)]
public bool TrailingStop { get; set; }
[Parameter("Add Pips", Group = "Trailing Stop", DefaultValue = 10, MinValue = 0, Step = 1)]
public double AddPips { get; set; }
[Parameter("Partial Position Close", DefaultValue = false, Group = "Protection")]
public bool partialclose { get; set; }
private MovingAverage Ma;
IchimokuKinkoHyo ichimoku;
private DateTime startTime;
private DateTime endTime;
protected override void OnStart()
{
ichimoku = Indicators.IchimokuKinkoHyo(periodFast, periodMedium, periodSlow);
Ma = Indicators.MovingAverage(SourceSeries, MaPeriods, MAType);
startTime = Server.Time.Date.AddHours(Begin);
endTime = Server.Time.Date.AddHours(Ending);
Print("Start Time {0},", startTime);
Print("End Time {0},", endTime);
}
protected override void OnBar()
{
var senkouA = ichimoku.SenkouSpanA.Last(1);
var senkouB = ichimoku.SenkouSpanB.Last(1);
var previousMa = Ma.Result.Last(1);
var closeprice = Bars.ClosePrices.Last(1);
var closeprice2 = Bars.ClosePrices.Last(2);
bool tradeTime = false;
var cond1 = (closeprice2 > senkouB & closeprice < senkouB);
var cond2 = (closeprice2 > senkouA & closeprice < senkouA);
var cond3 = closeprice > previousMa;
var cond4 = Bars.HighPrices.Last(4) < Bars.HighPrices.Last(2) & Bars.LowPrices.Last(4) < Bars.LowPrices.Last(2);
if(Begin < Ending) tradeTime = Server.Time.Hour >= Begin && Server.Time.Hour < Ending;
if(Ending < Begin) tradeTime = Server.Time.Hour >= Begin || Server.Time.Hour <= Ending;
if (!tradeTime) return;
if (Positions.Count == 0)
if (cond1 & cond2 & (cond3 | cond4))
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, InitialQuantity, MyLabel, StopLoss, TakeProfit);
}
if (TrailingStop)
{
TrailingStopAdjustment();
}
void TrailingStopAdjustment()
{
var positn = Positions.Find(MyLabel, SymbolName);
var allPositions = Positions.FindAll(MyLabel, SymbolName);
foreach (Position position in allPositions)
{
var entryPrice = position.EntryPrice;
var distance = entryPrice - Bars.ClosePrices.Last(1);
var NewSL = Bars.ClosePrices.Last(1) + (Symbol.PipSize * AddPips);
if (distance >= AddPips * Symbol.PipSize)
{
ModifyPosition(position, NewSL, position.TakeProfit, true);
Print("Stop Loss to Break Even set for SELL position {0}", position.Id);
if (partialclose)
ClosePosition(positn, position.Quantity / 10);
}
}
}
}
}
}
@gregory.bayard
gregory.bayard
15 Jan 2023, 17:13
RE:
hello,
it's quite simple, when the price crosses senkou span A and B on the downside, and at the same time it's above the 400 average, it should go back to the sell position except that during the backtest it goes back strangely even without crossing the senkou, I don't understand why
@gregory.bayard