Topics
Replies
Old Account
21 Jul 2014, 20:57
This was an example of how to use the Close() method.
If(SMA.Result.LastValue > 1) Close();
It is the same as the method for opening a position, but insted of opening a position it closes it.
So you have for your criteria for closing a position that is the IF("something") then close.
In the example i used all positions would close when the Simple Moving Average hit 1.
If you want the position to close when EMA is equal or less the the as you write it like this:
If(EMA.Result.LastValue <= Symbol.Ask) Close();
@Old Account
Old Account
20 Jul 2014, 19:23
Add this to you code
private void Close()
{
foreach (var position in Positions)
{
ClosePosition(position);
}
}
And when you want to close a position add Close()
Like this:
If(SMA.Result.LastValue > 1)
Close();
Hope it helped
@Old Account
Old Account
18 Jun 2014, 15:03
( Updated at: 21 Dec 2023, 09:20 )
RE: RE:
Spotware said:
MRSV said:
Hi
Saw this today, and wonderd if it were a chart bug or not
Found it a little hard to belive that GBPJPY jumped 3000 pips
Please specify Broker Name and Environment (live, demo).
LiquidMarkets demo account
@Old Account
Old Account
25 Apr 2014, 00:25
It looks good, but it's hard to say with just one image.
@Old Account
Old Account
22 Apr 2014, 23:08
RE:
Researcher said:
If there is no such position on tick the Find() method returns null. Try this code:
protected override void OnTick() { var position = Positions.Find("Test"); if (position != null) ClosePosition(position); }
Thank you !!!
@Old Account
Old Account
21 Mar 2014, 20:23
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { [Parameter("Fast Periods", DefaultValue = 10)] public int F_Periods { get; set; } [Parameter("Slow Periods", DefaultValue = 20)] public int S_Periods { get; set; } [Parameter("Volume", DefaultValue = 1000)] public int Volume { get; set; } public WeightedMovingAverage F_WMA; public WeightedMovingAverage S_WMA; public bool TradeS; public bool TradeB; protected override void OnStart() { F_WMA = Indicators.WeightedMovingAverage(MarketSeries.Close, F_Periods); S_WMA = Indicators.WeightedMovingAverage(MarketSeries.Close, S_Periods); } protected override void OnTick() { bool isBuyPositionOpen = Positions.Count != 0 && LastResult.Position.TradeType == TradeType.Buy; bool isSellPositionOpen = Positions.Count != 0 && LastResult.Position.TradeType == TradeType.Sell; if (S_WMA.Result.LastValue > F_WMA.Result.LastValue && !isSellPositionOpen && TradeS) { ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "", 20, 20); TradeS = false; } if (S_WMA.Result.LastValue < F_WMA.Result.LastValue && !isBuyPositionOpen && TradeB) { ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "", 20, 20); TradeB = false; } } protected override void OnBar() { TradeS = true; TradeB = true; } } }
@Old Account
Old Account
11 Mar 2014, 19:05
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class cAlgoForum : Robot { public int FailTradeCount; public int TradeCooldown; protected override void OnStart() { Positions.Closed += PositionsOnClosed; FailTradeCount = 0; TradeCooldown = 0; } protected override void OnTick() { double Median_P10 = MarketSeries.Median.LastValue + (10 * Symbol.PipSize); double Median_M10 = MarketSeries.Median.LastValue - (10 * Symbol.PipSize); bool Check_1 = Symbol.Spread <= 5; bool Check_2 = Positions.Count <= 2; bool Check_3 = FailTradeCount <= 0; bool Chech_4 = TradeCooldown <= 0; bool Check_5B = Symbol.Ask >= Median_P10; bool Check_5S = Symbol.Ask <= Median_M10; if (Check_1 && Check_2 && Check_3 && Chech_4 && Check_5B) ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "Buy", 20, 40); if (Check_1 && Check_2 && Check_3 && Chech_4 && Check_5S) ExecuteMarketOrder(TradeType.Sell, Symbol, 10000, "Sell", 20, 40); Print("{0}{1}", Check_5S, Check_5B); } private void PositionsOnClosed(PositionClosedEventArgs args) { var position = args.Position; if (position.GrossProfit < 0) FailTradeCount = 10; if (position.EntryTime == DateTime.Now) TradeCooldown = 2; } protected override void OnBar() { FailTradeCount = FailTradeCount - 1; TradeCooldown = TradeCooldown - 1; } } }
@Old Account
Old Account
08 Mar 2014, 17:30
I think if I were to calculate the angle like the Ray chart tool I will need to know the scale to see the distanse in pips one hour is equal to.
Are there any ways to do that ?
@Old Account
Old Account
05 Mar 2014, 19:42
Sorry, I posted it in Indicator Development Support by mistake and i wasn't able to delete it.
@Old Account
Old Account
02 Mar 2014, 00:57
I'm not shure i understan what you are looking for, could you explane it a bit more?
@Old Account
Old Account
01 Mar 2014, 00:11
protected override void OnTick()
{
Print(Server.Time);
}
@Old Account
Old Account
28 Jan 2014, 00:27
Well its not -7.36039, It's -0,0000736039.
-7.36039-E05 = -7.36039*10^-5 <=> -0,0000736039.
@Old Account
Old Account
26 Jan 2014, 01:35
RE:
MrSvensli@hotmail.no *
I would be happy to help you, but i don't have much experience whit Ichimoku so you are going to have to explainit a bit more for me. You can contact me at MrSvesli@hotmail.no if you to.
@Old Account
Old Account
30 May 2016, 16:58
RE: RE:
MRSV said:
@Old Account