Experts: Safe Trend Scalp - page 8

 
LONNV #: this is because object trendline value take from barshift 0, but in formula value , index value take from 2nd coordinate point. if index value in formula value zero, they will be nearly same.

No! Do you even understand what the ObjectGetValueByShif() does?

The function, does exactly the same thing as the "y=mx+c" equation. It calculates the price for the bars either inside or outside of the two connecting points of the trend-line.

Here is an example code of a Script, to demonstrate the two methods, that has been fully tested with log results:

#property strict
#property script_show_inputs

// Script input parameters
   input uint
      nStartPointBarShift  = 5,     // Bar shift of starting point of trend-line
      nEndPointBarShift    = 15,    // Bar shift of ending   point of trend-line
      nQueryPointBarShift  = 10;    // Bar shift of query    point of trend-line

// Script start event handler
   void OnStart()
   {
      // Check if parameters are acceptable
         if( nStartPointBarShift == nEndPointBarShift )
         {
            Print( "Invalid Parameters!" );
            return;
         };

      // Calculate values
         int
            nDeltaBarShift    = (int) nEndPointBarShift - (int) nStartPointBarShift;   // Change in bar shift

         datetime
            dtStartPointTime  = iTime( _Symbol, _Period, nStartPointBarShift ),        // Time at starting point
            dtEndPointTime    = iTime( _Symbol, _Period, nEndPointBarShift   );        // Time at ending point

         double
            dbStartPointPrice = iClose( _Symbol, _Period, nStartPointBarShift ),       // Price at starting point
            dbEndPointPrice   = iClose( _Symbol, _Period, nEndPointBarShift   ),       // Price at ending point
            dbDeltaPrice      = dbEndPointPrice - dbStartPointPrice,                   // Change in price
            dbLineSlope       = dbDeltaPrice / nDeltaBarShift,                         // Slope  is the value of "m"
            dbOffset          = dbEndPointPrice - dbLineSlope * nEndPointBarShift;     // Offset is the value of "c"

      // Draw trend-line object
         string sObjectName = "Test-Trendline";
         if( ObjectCreate( sObjectName, OBJ_TREND, 0, // Create trend-line object
               dtStartPointTime, dbStartPointPrice,   // Starting point of trend-line
               dtEndPointTime,   dbEndPointPrice ) )  // Ending   point of trend-line
         {
            // Get price by both methods
               double
                  dbValueByShift = ObjectGetValueByShift( sObjectName, nQueryPointBarShift ),
                  dbPriceByShift = dbLineSlope * nQueryPointBarShift + dbOffset;

            // Print out the values to the log
               PrintFormat( "Starting Point: %s @ %d",                            DoubleToString( dbStartPointPrice, _Digits ), nStartPointBarShift );
               PrintFormat( "Ending   Point: %s @ %d",                            DoubleToString( dbEndPointPrice,   _Digits ), nEndPointBarShift   );
               PrintFormat( "Query    Point: %s @ %d (by ObjectGetValueByShift)", DoubleToString( dbValueByShift,    _Digits ), nQueryPointBarShift );
               PrintFormat( "Query    Point: %s @ %d (by y=mx+c calculation)",    DoubleToString( dbPriceByShift,    _Digits ), nQueryPointBarShift );

            // Delete Object
               ObjectDelete( sObjectName );  // Delete trend-line object
         };
   };
2022.04.25 00:07:12.139 Compiling '(Test)\TestTrendlineValue'
2022.04.25 00:07:53.150 Script (Test)\TestTrendlineValue EURUSD,H1: loaded successfully
2022.04.25 00:07:56.080 TestTrendlineValue EURUSD,H1 inputs: nStartPointBarShift=5; nEndPointBarShift=15; nQueryPointBarShift=10; 
2022.04.25 00:07:56.111 TestTrendlineValue EURUSD,H1: initialized
2022.04.25 00:07:56.111 TestTrendlineValue EURUSD,H1: Starting Point: 1.07855 @ 5
2022.04.25 00:07:56.111 TestTrendlineValue EURUSD,H1: Ending   Point: 1.07973 @ 15
2022.04.25 00:07:56.111 TestTrendlineValue EURUSD,H1: Query    Point: 1.07914 @ 10 (by ObjectGetValueByShift)
2022.04.25 00:07:56.111 TestTrendlineValue EURUSD,H1: Query    Point: 1.07914 @ 10 (by y=mx+c calculation)
2022.04.25 00:07:56.111 TestTrendlineValue EURUSD,H1: uninit reason 0
2022.04.25 00:07:56.111 Script TestTrendlineValue EURUSD,H1: removed
 
seems good.. will it take trade automatically?
 
Hi there! does it work with real accounts? Thanks for your answer!