Skip to content

Commit

Permalink
Aggiungere i file di progetto.
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonardoCiaccio committed May 21, 2020
1 parent dba1f0b commit 4723713
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SAR Trailing Stop
Un Tool molto comodo per spostare lo stoploss con il SAR

[Pagina ufficiale](https://ctrader.guru/product/sar-trailing-stop/)
Binary file added SAR Trailing Stop.algo
Binary file not shown.
20 changes: 20 additions & 0 deletions SAR Trailing Stop.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SAR Trailing Stop", "SAR Trailing Stop\SAR Trailing Stop.csproj", "{616A444A-C219-43E4-B836-B75B7C8E00E2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{616A444A-C219-43E4-B836-B75B7C8E00E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{616A444A-C219-43E4-B836-B75B7C8E00E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{616A444A-C219-43E4-B836-B75B7C8E00E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{616A444A-C219-43E4-B836-B75B7C8E00E2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
16 changes: 16 additions & 0 deletions SAR Trailing Stop/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("SAR Trailing Stop")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyProduct("SAR Trailing Stop")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]

[assembly: Guid("35f19c43-c7cc-4f53-b8e0-61caaf9cd8e8")]

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
143 changes: 143 additions & 0 deletions SAR Trailing Stop/SAR Trailing Stop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/* CTRADER GURU --> Indicator Template 1.0.6
Homepage : https://ctrader.guru/
Telegram : https://t.me/ctraderguru
Twitter : https://twitter.com/cTraderGURU/
Facebook : https://www.facebook.com/ctrader.guru/
YouTube : https://www.youtube.com/channel/UCKkgbw09Fifj65W5t5lHeCQ
GitHub : https://github.com/ctrader-guru
*/

using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{

[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class SARTrailingStop : Robot
{

#region Enums

#endregion

#region Identity

/// <summary>
/// Nome del prodotto, identificativo, da modificare con il nome della propria creazione
/// </summary>
public const string NAME = "SAR Trailing Stop";

/// <summary>
/// La versione del prodotto, progressivo, utilie per controllare gli aggiornamenti se viene reso disponibile sul sito ctrader.guru
/// </summary>
public const string VERSION = "1.0.2";

#endregion

#region Params

[Parameter(NAME + " " + VERSION, Group = "Identity", DefaultValue = "https://ctrader.guru/product/sar-trailing-stop/")]
public string ProductInfo { get; set; }

[Parameter("Min AF", Group = "Params", DefaultValue = 0.02, MinValue = 0)]
public double MinAF { get; set; }

[Parameter("Max AF", Group = "Params", DefaultValue = 0.2, MinValue = 0)]
public double MaxAF { get; set; }

[Parameter("Auto Stop ?", Group = "Params", DefaultValue = true)]
public bool AutoStop { get; set; }

#endregion

#region Property

#endregion

#region cBot Events

protected override void OnStart()
{

// --> Stampo nei log la versione corrente
Print("{0} : {1}", NAME, VERSION);

}

protected override void OnTick()
{

// --> Fermiamo in automatico
_checkAutoStop();

}

protected override void OnBar()
{

// --> Al momento le API non forniscono un metodo per ottenere tutte le posizioni di un simbolo se non per LABEL
// --> quindi devo ciclare
foreach (var position in Positions)
{

if (position.SymbolName != SymbolName) continue;

bool canModify = false;
double SARlevel = Math.Round(Indicators.ParabolicSAR(MinAF, MaxAF).Result.LastValue, Symbol.Digits);

switch (position.TradeType)
{
case TradeType.Buy:

canModify = (SARlevel < Bid);

break;

case TradeType.Sell:

canModify = (SARlevel > Ask);

break;

}

if (canModify && SARlevel != position.StopLoss) ModifyPositionAsync(position, SARlevel, position.TakeProfit);

}

}

#endregion

#region Private Methods

private void _checkAutoStop()
{

if (!AutoStop) return;

foreach (var position in Positions)
{

if (position.SymbolName != SymbolName) continue;

// --> Ok c'è una posizione interrompo e basta
return;

}

// --> Se non ho interrotto vuol dire che non c'è nulla per noi, quindi fermo tutto;
Stop();

}

#endregion

}

}
58 changes: 58 additions & 0 deletions SAR Trailing Stop/SAR Trailing Stop.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{616A444A-C219-43E4-B836-B75B7C8E00E2}</ProjectGuid>
<ProjectTypeGuids>{DD87C1B2-3799-4CA2-93B6-5288EE928820};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>cAlgo</RootNamespace>
<AssemblyName>SAR Trailing Stop</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="cAlgo.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3499da3018340880, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\API\cAlgo.API.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="SAR Trailing Stop.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

0 comments on commit 4723713

Please sign in to comment.