Convert PRT to C#
Convert PRT to C#
07 Jan 2023, 14:45
hello everyone! would there be a generous soul who could convert this code of the ProRealTime platform to C# please, I am still an amateur in C# and it would help me a lot
// HORAIRE DE TRADING---------------------------------------------------------------------------------------
noEntryBeforeTime = 090000
timeEnterBefore = time >= noEntryBeforeTime
noEntryAfterTime = 110000
timeEnterAfter = time < noEntryAfterTime
// JOUR DE TRADING------------------------------------------------------------------------------------------
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// INDICATEUR-----------------------------------------------------------------------------------------------
indicator1 = SenkouSpanB[9,26,52]
c1 = (close CROSSES UNDER indicator1)
indicator2 = SenkouSpanA[9,26,52]
c2 = (close CROSSES UNDER indicator2)
indicator3 = Average[435](close)
c3 = (close > indicator3)
IF (c1 AND c2 and (c3 or (high[3]<high[1]and low[3]<low[1] )))AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry and tally < maxTrades THEN
sellshort 1 CONTRACT AT MArket
partial=0
ENDIF
// CLOTURE PARTIELLE----------------------------------------------------------------------------------------
IF shortonmarket and positionperf>0.10/100 and partial=0 THEN
exitshort 0.1 contract at market
partial = 1
ENDIF
// NOMBRE MAX DE TRADE JOURNALIER---------------------------------------------------------------------------
ONCE maxTrades = 10
ONCE tally = 0
IF intradayBarIndex = 0 THEN
tally = 0
ENDIF
newTrades = (onMarket and not onMarket[1]) or ((not onMarket and not onMarket[1]) and (strategyProfit <> strategyProfit[1])) or (longOnMarket and ShortOnMarket[1]) or (longOnMarket[1] and shortOnMarket) or ((tradeIndex(1) = tradeIndex(2)) and (barIndex = tradeIndex(1)) and (barIndex > 0) and (strategyProfit = strategyProfit[1]))
IF newTrades THEN
tally = tally +1
ENDIF
ONCE maxOrdersL = 1 //long
ONCE maxOrdersS = 1 //short
IF intradayBarIndex = 0 THEN
ordersCountL = 0
ordersCountS = 0
ENDIF
IF longTriggered then
ordersCountL = ordersCountL + 1
ENDIF
IF shortTriggered then
ordersCountS = ordersCountS + 1
ENDIF
// STRATEGY PROFITS-----------------------------------------------------------------------------------------
set stop %loss 1
set target %profit 0.23
IF Not OnMarket THEN
TrailStart = 2.45
BasePerCent = 0.000
StepSize = 1
PerCentInc = 0.000
BarNumber = 10
BarPerCent = 0.235
RoundTO = -0.5
PriceDistance = 9 * pipsize
y2 = 0
ProfitPerCent = BasePerCent
TradeBar = BarIndex
ELSIF ShortOnMarket AND close < (TradePrice - (y2 * pipsize)) THEN
x2 = (tradeprice - close) / pipsize
IF x2 >= TrailStart THEN
Diff2 = abs(TrailStart - x2)
Chunks2 = max(0,round((Diff2 / StepSize) + RoundTO))
ProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc))
BarCount = BarIndex - TradeBar
IF BarCount MOD BarNumber = 0 THEN
ProfitPerCent = ProfitPerCent + BarPerCent
ENDIF
//
ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))
y2 = max(x2 * ProfitPerCent, y2)
ENDIF
ENDIF
IF y2 THEN
ExitPrice = Tradeprice - (y2 * pipsize)
IF abs(close - ExitPrice) > PriceDistance THEN
IF close <= ExitPrice THEN
EXITSHORT AT ExitPrice STOP
ELSE
EXITSHORT AT ExitPrice LIMIT
ENDIF
ELSE
EXITSHORT AT Market
ENDIF
ENDIF
// END------------------------------------------------------------------------------------------------------
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
PanagiotisChar
10 Jan 2023, 08:40
Hi,
I don't know what the code is supposed to do, so I cannot advise
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar
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
Hi,
I don't know what the code is supposed to do, so I cannot advise
@gregory.bayard
PanagiotisChar
09 Jan 2023, 10:13
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.
Aieden Technologies
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar