Page 1 of 1

Help regarding trailing stop

Posted: Sat Aug 13, 2016 12:13 pm
by mohamedzaki
Good Day every body. I want to implement a trailing stop indicator or safety in my bot. I want want it to work only on the way up and not down in a sense close to what we use in forex. so say I would adjust it to sell my coins when the pririce drops 2 pecent. if the price goes up it will trail the new price and reset its value to 2 percent lower than the new price.I have tried the stop loss dynamic but it doesnt work the way I want it to work as its value goes up and down.

Re: Help regarding trailing stop

Posted: Sat Aug 13, 2016 2:29 pm
by stephan
You are very close to the solution. The selection of the dynamic stop-loss is indeed perfect, but you need to expand this with the dynamic roof-in. This will allow you to buy back again. (the stop-loss sells, the roof-in buys)

What also smart to do is add in 2 dynamic stop-losses and 2 dynamic roof-in safeties. If you set one for the long run and one for the short run then you will get better buying and selling signals.

I hope this helps.

Re: Help regarding trailing stop

Posted: Sat Aug 13, 2016 6:18 pm
by mohamedzaki
Hey Stephane

Thanks for the reply. in fact it doesnt matter what intereval I set the dynamic stop loss it still reacts in a different way. what we really need is a simple trailing stop which only tracks the price upwards and locks its value. when the price goes down and hits the stop loss line then the bot will sell. the same with the roof in and out. it makes more sense to move only in one direction. Thanks

Image

Re: Help regarding trailing stop

Posted: Sat Aug 13, 2016 8:57 pm
by pshai
They actually have that in Haasbot: Price Pump and Price Dump. They try to mimic what you're saying, but they cannot actually do it as you're referring; there are no links between safeties, indicators and insurances, nor the history and/or actions of the bot itself. So it's impossible to do what you're saying.

I might be wrong though, but I think this is the case.


~pshai

Re: Help regarding trailing stop

Posted: Wed Sep 14, 2016 4:30 am
by jonfelz
I tried making a trailing stop with it months ago and could never succeed. When I asked for help, I got the same response that you received. I have basically quit posting to the forum and will probably not use this software after my subscription ends because it has just been headache after headache. I like their setup, but it seems that things just never work as intended, but they sell it as a finished product.

Re: Help regarding trailing stop

Posted: Wed Sep 14, 2016 5:53 am
by Theo
Price Pump is trailing stop direction up. Price Dump is trailing stop on the way down.

They actually have that in Haasbot: Price Pump and Price Dump. They try to mimic what you're saying, but they cannot actually do it as you're referring; there are no links between safeties, indicators and insurances, nor the history and/or actions of the bot itself. So it's impossible to do what you're saying.



A trailing stop has nothing to do with any indicators, insurances or safeties. It has to do with the price alone.

Re: Help regarding trailing stop

Posted: Wed Sep 14, 2016 9:10 am
by pshai
jonfelz wrote:I like their setup, but it seems that things just never work as intended, but they sell it as a finished product.

Exactly. They are taking too bid piece at once, developing the software all-around, instead of concentrating in single stuff and making sure they work first. And another thing is, they rarely understand what you are saying when you mention a problem, because the devs don't see it that way.

But, here's something that might help you (I never got it working and gave up; no idea what is wrong with it...):

Code: Select all

/*
* Created by SharpDevelop.
* User: pshai
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TradeServer.ScriptingDriver.DataObjects;
using TradeServer.ScriptingDriver.Interfaces;
using TicTacTec.TA.Library;

namespace PshaisSafeties
{
   public class pshaisPricePump : ISafetyScript
   {
      double _value, _atrMult = 2;
      int _length = 25;
      
      public string Name
      {
         get { return "pshai's Price Pump"; }
      }
      public int TicksBack
      {
         get { return Core.AtrLookback(_length); }
      }
      
      public List<ScriptParameter> GetParameters()
      {
         List<ScriptParameter> res = new List<ScriptParameter>();
      
         res.Add(new ScriptParameter("Length", ScriptParameterType.Integer, _length.ToString()));
         res.Add(new ScriptParameter("ATR Multiplier", ScriptParameterType.Decimal, _atrMult.ToString()));
      
         return res;
      }
      
      public void SetParameters(Dictionary<string, object> parameters)
      {
         foreach (var item in parameters)
         {
            if( item.Value == null )
               continue;
         
            if (item.Key == "Length") { _length = Convert.ToInt32(item.Value.ToString()); }
            if (item.Key == "ATR Multiplier") { _atrMult = Convert.ToDouble(item.Value.ToString()); }
         }
      }
      
      // Chart lines
      public List<ChartRecord> GetChartLines()
      {
         List<ChartRecord> chartLines = new List<ChartRecord>();
         chartLines.Add(new ChartRecord() { ChartIndex = 0, Name = "Pump Bar", HexLineColor = "#FF0000" });
         
         return chartLines;
      }
      public List<decimal> GetChartData()
      {
         List<decimal> chartData = new List<decimal>();
         chartData.Add(Convert.ToDecimal(_value));
         
         return chartData;
      }
      
      
      public void Init()
      {

      }

      
      public SafetyResult GetResult(SafetyContext context)
      {
         try
         {
            var position = context.PriceInstrument.Close.Length - (1 + context.Offset);
            var high = context.PriceInstrument.High;
            var low = context.PriceInstrument.Low;
            var close = context.PriceInstrument.Close;
            var datalen = close.Length;
            
            
            int beginLong, outLenLong;
            var outLong = new double[datalen];
            
            var retcodeLong = Core.Atr( 0, datalen-1, high, low, close, _length, out beginLong, out outLenLong, outLong );
            
            // Chandelier Exit SHORT
            if( retcodeLong == Core.RetCode.Success )
            {
               if( outLenLong > 0 )
               {
                  var output = new double[datalen];
                  CalculatePump(context, beginLong, datalen, outLong, _length, _atrMult, output);
                  
                  _value = output[position];
                  if( close[position] < _value )
                     return SafetyResult.SellShort;
               }
               else
                  context.Logger.LogToFile(string.Format("Bad output length: {0}", outLenLong));
            }
            else
               context.Logger.LogToFile(string.Format("Bad RetCode: {0}", retcodeLong));
         }
         catch (Exception ex) // This try catch block is an highly recommend practice
         {
            context.Logger.LogToFile(string.Format("Exception detected: {0}", ex.StackTrace));
         }
         
         return SafetyResult.DoNothing; // Default output
      }
      
      void CalculatePump(SafetyContext context, int beginIndex, int endIndex, double[] atrIn, int len, double atrMult, double[] output)
      {
         try {
            var _lastChanLong = double.MinValue;
            var high = context.PriceInstrument.High;
            var low = context.PriceInstrument.Low;
            var close = context.PriceInstrument.Close;
            
            for( int i = 0; i < endIndex; i++ )
            {
               var j = beginIndex + i;
               var highestHigh = high.Where( (val, index) => (index >= j - len && index <= j)).Max();
               var atr = atrIn[i];
               var chanLong = highestHigh - atr * atrMult;
               
               var candle = Math.Min( low[j], close[j] );
               
               // Don't allow going downwards
               if( chanLong < _lastChanLong)
                  chanLong = _lastChanLong;
               else
                  _lastChanLong = chanLong;
               
               if( candle < chanLong ) // if we get a hit..
                  _lastChanLong = double.MinValue; // ..reset for next iteration
               
               //_value = chanLong;
               output[j] = chanLong;
            }
         }
         catch (Exception ex)
         {
            context.Logger.LogToFile(string.Format("Exception detected: {0}", ex.StackTrace));
         }
      }
   }
}

Re: Help regarding trailing stop

Posted: Thu Sep 15, 2016 8:46 am
by Theo
Again just to be clear.

Price pump is trailing stop up and Price dump is trailing stop down.

pshai , Trailing stops have nothing to do with indicators communicating with each other. It is based on price.

Re: Help regarding trailing stop

Posted: Thu Sep 15, 2016 12:30 pm
by stephan
Exactly. They are taking too bid piece at once, developing the software all-around, instead of concentrating in single stuff and making sure they work first. And another thing is, they rarely understand what you are saying when you mention a problem, because the devs don't see it that way.

No you are wrong and i am getting tired of this.

First of all, we tell you how it works. If we have implemented methods and explain how it works to you. You might have a idea, sure, but this does not mean we have to change the full software for you. It does also not mean we are wrong.

Sure your Candelier stop-loss (yeah i see it, i know it) is a different implementation. I told you to reach out to me if you are scripting so i can make sure it works. But no, i saw no email or live chat message, instead i see it posting on the forum with another complain.

Same goes for discussions, if you know better then stay inside the discussion and defend it, do not run.

This is my last warning, stop this, act like a human being, ask for help when needed and act normal else i will ban you.

jonfelz wrote:I tried making a trailing stop with it months ago and could never succeed. When I asked for help, I got the same response that you received. I have basically quit posting to the forum and will probably not use this software after my subscription ends because it has just been headache after headache. I like their setup, but it seems that things just never work as intended, but they sell it as a finished product.


Please reach out to us on the live chat and we will help you fully understand how to approach it. In a day you will be noting down your first profits, count on it because its just true.

Re: Help regarding trailing stop

Posted: Thu Sep 15, 2016 12:40 pm
by stephan
mohamedzaki wrote:Hey Stephane

Thanks for the reply. in fact it doesnt matter what intereval I set the dynamic stop loss it still reacts in a different way. what we really need is a simple trailing stop which only tracks the price upwards and locks its value. when the price goes down and hits the stop loss line then the bot will sell. the same with the roof in and out. it makes more sense to move only in one direction. Thanks


This is true indeed. The time interval is not impacting the safeties, because safeties always must run each minute. So the field you have to adjust the the "adjustment time". This can make a stop-loss adjust faster or slower.