Topics
Replies
PsykotropyK
11 Oct 2012, 17:39
Sure it is triggered with the bar but also with the tick. My problem currently is that my code (for reasons beyhond my current understanding) give erratic behavior. When I load the indicator, it is properly calculated on historical data. When tick occured, it has trouble to always identify a previous high or previous low. It work better if I use a shift = 1 as every tick will launch a calculation based on previous bars only. But still there are a few errors that never occur when the process is launch on historical datas. So the idea it to always do the calculation on the past 2/3 bars.
I'll check the code ASAP and let you know. If everything's fine, I'll post the indicator.
@PsykotropyK
PsykotropyK
11 Oct 2012, 14:42
By the way, to force a recalc, I'm thinking on changing Calculate(int i) by Calculate(int index) and then having a for(int i=index-j; i<=index; i++) and add j as a parameter
@PsykotropyK
PsykotropyK
11 Oct 2012, 14:40
Hi again,
I changed my MajorTrend/MinorTrend data to an array for 2 reasons :
- I want to recalculate on several bar (1 or 2) every time because I realized looking at my indicator on real time that it has some erratic behaviour on the current bar, and so I wanna be sure that if it has it, it won't record a false value
- I want to be able to create an other indicator that will show the major and minor trend.
Unfortunately, it doesn't work. The only differences with previous code is the correction you gave me (admin) and that I took out every calculation from the initialize part.
using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = true)] public class SupportResistance: Indicator { [Output("Resist")] public IndicatorDataSeries LineResist { get; set; } [Output("Support")] public IndicatorDataSeries LineSupport { get; set; } [Parameter("Shift", DefaultValue = 0)] public int Shift{ get; set; } public int[] TrendMinor; //1 = Bullish ^ -1 = Bearish v public int[] TrendMajor; protected override void Initialize() { } public override void Calculate(int i) { //Array.Resize(ref TrendMinor, TrendMinor.Length + 1); //Array.Resize(ref TrendMajor, TrendMajor.Length + 1); if(i < Shift + 2) { TrendMajor[i - Shift] = 1; TrendMinor[i - Shift] = 1; LineResist[i - Shift] = MarketSeries.High[i - Shift]; LineSupport[i - Shift] = MarketSeries.Low[i - Shift]; return; } LineResist[i - Shift] = LineResist[i - Shift - 1]; LineSupport[i - Shift] = LineSupport[i - Shift - 1]; //+------------------------------------------------------------------+ // MAJOR TREND REVERSAL CALCULATION //+------------------------------------------------------------------+ if(TrendMajor[i - Shift - 1] == 1 && MarketSeries.Low[i - Shift] < LineSupport[i - Shift]) { TrendMajor[i - Shift] = -1; TrendMinor[i - Shift] = -1; } else if(TrendMajor[i - Shift - 1] == -1 && MarketSeries.High[i - Shift] > LineResist[i - Shift]) { TrendMajor[i - Shift] = 1; TrendMinor[i - Shift] = 1; } else { TrendMajor[i - Shift] = TrendMajor[i - Shift - 1]; TrendMinor[i - Shift] = TrendMinor[i - Shift - 1]; } //+------------------------------------------------------------------+ // Find Signals //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ // MAJOR BULLISH TREND //+------------------------------------------------------------------+ if(TrendMajor[i - Shift] == 1) { //--- Bullish TrendMinor if(TrendMinor[i - Shift] == 1) { if(MarketSeries.High[i - Shift] < MarketSeries.High[i - Shift - 1]) { //--- End of bullish TrendMinor if(MarketSeries.High[i - Shift - 1] > LineResist[i - Shift - 1]) { LineResist[i - Shift] = MarketSeries.High[i - Shift - 1]; } TrendMinor[i - Shift] = -1; } } else //--- Bearish TrendMinor { if(MarketSeries.Low[i - Shift] > MarketSeries.Low[i - Shift - 1]) { //--- End of bearish TrendMinor if(MarketSeries.Low[i - Shift - 1] > LineSupport[i - Shift - 1]) { LineSupport[i - Shift] = MarketSeries.Low[i - Shift - 1]; } TrendMinor[i - Shift] = 1; } } } //+------------------------------------------------------------------+ // MAJOR BEARISH TREND //+------------------------------------------------------------------+ else { //--- Bearish TrendMinor if(TrendMinor[i - Shift] == -1) { if(MarketSeries.Low[i - Shift] > MarketSeries.Low[i - Shift - 1]) { //--- End of bullish TrendMinor if(MarketSeries.Low[i - Shift - 1] < LineSupport[i - Shift - 1]) { LineSupport[i - Shift] = MarketSeries.Low[i - Shift - 1]; } TrendMinor[i - Shift] = 1; } } else //--- Bullish TrendMinor { if(MarketSeries.High[i - Shift] < MarketSeries.High[i - Shift - 1]) { //--- End of bullish TrendMinor if(MarketSeries.High[i - Shift - 1] < LineResist[i - Shift - 1]) { LineResist[i - Shift] = MarketSeries.High[i - Shift - 1]; } TrendMinor[i - Shift] = -1; } } } } } }
@PsykotropyK
PsykotropyK
11 Oct 2012, 14:26
Nice job for finalizing the robot.
Did you run a backtest on it? If so can you put the results?
@PsykotropyK
PsykotropyK
10 Oct 2012, 17:17
Thanks.
Still got a few issues to deal with, I will consider posting my indicator if it works the way I want.
Ciao
@PsykotropyK
PsykotropyK
09 Oct 2012, 22:05
Non ça va j'ai pas de problème avec le français, mais ça serait simplement plus facile pour toi pour avoir des réponses.
Anyway, there is an over flaw in your strategy if I'm right. You don't take into account in your examples the cost of your trades (comission + spread). The more you have consecutive losses, the more this part take importance. Lets say your broker cost you 2 pip per operation and 4 consecutive before a gain :
R1 : +20 R2 : -20 Broker : -4
R1 : +20 R2 : -40 Broker : -6
R1 : +20 R2 : -80 Broker : -10
R1 : +20 R2 : -160 Broker ; -18
R1 : -20 R2 : +320 broker : -34
Total : +8
If you add one consecutive loss, you start loosing money. Anyway, I wish you good luck.
@PsykotropyK
PsykotropyK
09 Oct 2012, 14:58
A few things :
1) why do you keep talking in french while 99% of the people here don't? Except if you are not really trying to look for answers.
3) your strategy can only work with a very high equity. Let's imagine your robot end up giving 12 consecutive win on robot 1 (R1), followed by a 13th as a loss. Robot 2 (R2) will have 12 consecutive losses before its win. If I neglate the fees & bid ask your output will be (following your 20pip S/L & 10k trades) :
12th trade : R1 PnL --> 20*12 = 240 euros /// R2 PnL --> -20*2^12 + 20 = -81.900 euros /// TOTAL = -81.660 euros
13th trade : R1 PnL --> 20*12-20 = 220 euros /// R2 PnL --> 20 /// TOTAL = + 240 euros
If you want to know what equity you should have :
Equity = -[v * S/L * 2 ^ cL] + v * SL * (cL + 1)] with v = volume ; SL : stop loss in value (ie 20pip EUR/USD = 0.002), cL = estimated max consecutive losses.
As you can see it's an exponential curve. Regarding that your trade opening decision is random it is not very hard to estimate your chances to reach 10 or more consecutive loss on one robot as very close from 1. On a simple excel spreadsheets, using a random number generator as your robot output (50% chances win, 50% chances loss), and doing around 131k random consecutive shots, I easily reach series of 15/16 consecutive loss on one of the robot and it can go even higher. With 15 consecutives, you would end up making 300€ for a need of 660.000€ equity more or less.
Martingale is a very dangerous tool if your entry decision is not filtered.
@PsykotropyK
PsykotropyK
25 Sep 2012, 08:55
upPrev & downPrev are set as the last existing up or down line. They are set up at every changes in the line values, and should be kept (if my code is good) for the next tick.
Anyway, Ill try with Print.
About print, I have a problem, on a OnBar, I try to get open and close values of the bar. So I use the following code :
protected override void OnBar() { double cl = MarketSeries.Close[MarketSeries.Close.Count - 1]; double op = MarketSeries.Open[MarketSeries.Open.Count - 1]; Print("cl: {0}", cl); Print("op: {0}", op); }
The result is that cl and op got same values, the open price (see screen). How can it be???? To be more precise :
@PsykotropyK
PsykotropyK
24 Sep 2012, 15:39
Your graph doesn't say if the 1.29688 weren't hit. It's a H1 graph, with a line (close??) and not candles. In other words, the current value at 1.29041 doesn't represent all the value between 10:00 and when you took the snapshot. Moreover, the previous close was around 1.295, it may have goes up until 1.3, and then drop to 1.29041, triggering your SL. Check the candles (can't do it for you, I don't have access to CTrader here)
@PsykotropyK
PsykotropyK
22 Sep 2012, 16:01
An other thing, is your reference at the first line of your code? I just try a new robot an put it after the first comment : didn't work. Put it back first line, work perfectly
@PsykotropyK
PsykotropyK
22 Sep 2012, 11:33
My solution was only to add
using cAlgo.Indicators;
I'm not sure it will help, but change your reference to your indicator by
//#reference: ..\Indicators\AroonHorn.algo
It will prevent any errors if you change your directories, computer name, ...
Fr the rest, in your AroonHorn indicator, is the class declared at the begining is named AroonHorn (I don't know much C# but it should be this name that you call)
public class AroonHorn : Indicator
Then check that your parameters declaration is in the same order in your indicator and in your robot. If not, copy past the exact error
@PsykotropyK
PsykotropyK
20 Sep 2012, 09:08
Ok indeed something was wrong with my robot code :) Creating a robot miss the line "using cAlgo.Indicators;" Now its fixed and working
@PsykotropyK
PsykotropyK
18 Sep 2012, 10:50
If the problem is coming from my robot's code, then it should be easy to find, everything's in the thread (the only code so far is calling the indicator). If you are talking about the indicator's code, well it's working pretty well.
@PsykotropyK
PsykotropyK
18 Sep 2012, 09:21
I try to add the #eference line issued from my indicator to my robot at the beginning but it didn't changed anything
@PsykotropyK
PsykotropyK
18 Sep 2012, 09:14
Little typo: seems that the code insertion doesn't want to write <TrendFinder> after getindicator, but my code does :)
@PsykotropyK
PsykotropyK
18 Sep 2012, 09:10
Unfortunately it doesn't work. I referenced my indicator, which added a #reference line at line 1 with the complete file path. Then, I put your code lines
private TrendFinder trendFinder; protected override void OnStart() { // Put your initialization logic here trendFinder = Indicators.GetIndicator(StdDevMultiplier, StdDevPeriod, MAType); } protected override void OnTick() { // Put your core logic here Print("{0}", trendFinder.UpTrend.LastValue); }
When I build the robot, I got this error : "The type or namespace name 'TrendFinder' could not be found are you using directive or an assembly reference?)". I checked the spelling, and there are no typo with the name. I tried with 2 other indicators that I downloaded here, and call the added reference raise the same error.
@PsykotropyK
PsykotropyK
17 Sep 2012, 12:43
Thanks, I'll try this tomorrow (no access to cAlgo for now) :)
@PsykotropyK
PsykotropyK
12 Oct 2012, 19:31
Does contractual agreement forbid users of your forum to post the broker they found? ^^
Found 2/3 so far
@PsykotropyK