closed opened position by time
closed opened position by time
28 Feb 2015, 10:45
how close opened position by time (expire in sec.) ?
(in cAlgo cbot) with support optimizatoin in tester
Replies
quasar888
28 Feb 2015, 12:45
DateTime time;
void timeclosingtrad()
{time=Server.Time;
int timespanchoice=0;
foreach (Position item in Positions)
{
}
}
@quasar888
quasar888
28 Feb 2015, 12:48
RE:
DateTime time;
void timeclosingtrade()
{time=Server.Time;
int timespanchoice=0;
foreach (Position item in Positions)
{
if(item.EntryTime<time..AddHours(-timespanchoice))
{
ClosePosition(item);
}
}
}
protected override void OnStart()
{
Timer.Start(1);
}
protected override OnTimer()
{
timeclosingtrade();
}
@quasar888
edccde
03 Mar 2015, 00:51
RE: RE:
quasar888 said:
DateTime time;
void timeclosingtrade()
{time=Server.Time;
int timespanchoice=0;
foreach (Position item in Positions)
{if(item.EntryTime
{
ClosePosition(item);
}
}
}
protected override void OnStart()
{Timer.Start(1);
}
protected override OnTimer()
{
timeclosingtrade();
}
quasar you cool programmer ! but i cant insert right this code to expert, can you put your code to this expert (with 1 change parameter - expire open order in sec)
you`ll help me very well !!!
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Robots
{
[Robot]
public class NewRobot : Robot
{
[Parameter("Vol", DefaultValue = 10000)]
public int Vol { get; set; }
[Parameter("SL", DefaultValue = 300)]
public int SL { get; set; }
[Parameter("TP", DefaultValue = 400)]
public int TP { get; set; }
[Parameter("Tral_Start", DefaultValue = 200)]
public int Tral_Start { get; set; }
[Parameter("Tral_Stop", DefaultValue = 150)]
public int Tral_Stop { get; set; }
[Parameter("BB_price")]
public DataSeries BB_price { get; set; }
[Parameter("BB_period", DefaultValue = 20)]
public int BB_period { get; set; }
[Parameter("dev", DefaultValue = 2)]
public double dev { get; set; }
[Parameter("BB_type")]
public MovingAverageType BB_type { get; set; }
[Parameter("Period_K", DefaultValue = 5)]
public int Period_K { get; set; }
[Parameter("Period_D", DefaultValue = 3)]
public int Period_D { get; set; }
[Parameter("Slowing", DefaultValue = 3)]
public int Slowing { get; set; }
[Parameter("St_Ma_Type")]
public MovingAverageType St_Ma_Type { get; set; }
private BollingerBands BB;
private StochasticOscillator St;
private Position position1;
private int a;
protected override void OnStart()
{
Print("Welcome to the world of infinite financial possibilities!");
BB=Indicators.BollingerBands(BB_price,BB_period,dev,BB_type);
St=Indicators.StochasticOscillator(Period_K,Period_D,Slowing, St_Ma_Type);
}
protected override void OnPositionOpened(Position openedPosition)
{
position1 = openedPosition;
if (position1.TradeType == TradeType.Buy)
{
Trade.ModifyPosition(openedPosition, position1.EntryPrice-SL*Symbol.PointSize, position1.EntryPrice+TP*Symbol.PointSize);
Print("StopLoss and TakeProfit were successfully established");
}
if (position1.TradeType == TradeType.Sell)
{
Trade.ModifyPosition(openedPosition, position1.EntryPrice+SL*Symbol.PointSize, position1.EntryPrice-TP*Symbol.PointSize);
Print("StopLoss and TakeProfit were successfully established");
}
}
protected override void OnTick()
{
int bars=MarketSeries.Close.Count-1;
double h=MarketSeries.High[bars-1];
double l=MarketSeries.Low[bars-1];
double BB1=BB.Bottom[BB.Bottom.Count-2];
double BB2=BB.Top[BB.Top.Count-2];
double St1=St.PercentK[St.PercentK.Count-2];
double St2=St.PercentD[St.PercentD.Count-2];
double Bid=Symbol.Bid;
double Ask=Symbol.Ask;
double Point=Symbol.PointSize;
if (Trade.IsExecuting) return;
if (l<=BB1 && St1>St2 && a==0)
{
Trade.CreateBuyMarketOrder(Symbol, Vol);
Print("Trade BUY was successfully open");
a=1;
}
if (h>=BB2 && St1<St2 && a==0)
{
Trade.CreateSellMarketOrder(Symbol, Vol);
Print("Trade SELL was successfully open");
a=1;
}
foreach (var position in Account.Positions)
{
if(position.SymbolCode == Symbol.Code)
{
if(position.TradeType == TradeType.Buy)
{
if (Bid-position.EntryPrice>=Tral_Start*Point)
if (Bid-Tral_Stop*Point>=position.StopLoss)
Trade.ModifyPosition(position, Bid-Tral_Stop*Point, position.TakeProfit);
}
if(position.TradeType == TradeType.Sell)
{
if (position.EntryPrice-Ask>=Tral_Start*Point)
if (Ask+Tral_Stop*Point<=position.StopLoss)
Trade.ModifyPosition(position, Ask+Tral_Stop*Point, position.TakeProfit);
}
}
}
}
protected override void OnPositionClosed(Position pos)
{
a=0;
}
protected override void OnStop()
{
Print("The FxPro company wishes you successful day!");
}
}
}
Thanks!
I owe you
@edccde
edccde
04 Mar 2015, 15:04
RE: RE:
quasar888 said:
DateTime time;
void timeclosingtrade()
{time=Server.Time;
int timespanchoice=0;
foreach (Position item in Positions)
{if(item.EntryTime
{
ClosePosition(item);
}
}
}
protected override void OnStart()
{Timer.Start(1);
}
protected override OnTimer()
{
timeclosingtrade();
}
this code is wrong
i need code for close opened position after some seconds left (reduce time by timer) not in "X" hour
can you help?
@edccde
rina gupta
08 Mar 2015, 16:20
RE:
edccde said:
??
how close opened position by time (expire in sec.) ?
(in cAlgo cbot) with support optimizatoin in tester
@rina gupta
rina gupta
08 Mar 2015, 16:21
RE:
?????????????????????
quasar888 said:
DateTime time;
void timeclosingtrad()
{time=Server.Time;
int timespanchoice=0;
foreach (Position item in Positions)
{
}
}
@rina gupta
rina gupta
08 Mar 2015, 16:27
?????????????????????????????????????????????????????????????????????????????
@rina gupta
quasar888
28 Feb 2015, 12:45
DateTime time;
void timeclosingtrad()
{time=Server.Time;
int timespanchoice=0;
foreach (Position item in Positions)
{
}
}
@quasar888